Example usage for org.joda.time DateTime DateTime

List of usage examples for org.joda.time DateTime DateTime

Introduction

In this page you can find the example usage for org.joda.time DateTime DateTime.

Prototype

public DateTime() 

Source Link

Document

Constructs an instance set to the current system millisecond time using ISOChronology in the default time zone.

Usage

From source file:cd.education.data.collector.android.widgets.TimeWidget.java

License:Apache License

/**
 * Resets time to today./*from ww  w.j  ava2 s  .  co m*/
 */
@Override
public void clearAnswer() {
    DateTime ldt = new DateTime();
    mTimePicker.setCurrentHour(ldt.getHourOfDay());
    mTimePicker.setCurrentMinute(ldt.getMinuteOfHour());
}

From source file:cd.education.data.collector.android.widgets.TimeWidget.java

License:Apache License

@Override
public IAnswerData getAnswer() {
    clearFocus();//  www  . j av  a 2 s  . c  o m
    // use picker time, convert to today's date, store as utc
    DateTime ldt = (new DateTime()).withTime(mTimePicker.getCurrentHour(), mTimePicker.getCurrentMinute(), 0,
            0);
    //DateTime utc = ldt.withZone(DateTimeZone.forID("UTC"));
    System.out.println("storing:" + ldt);
    return new TimeData(ldt.toDate());
}

From source file:cd.go.contrib.elasticagents.marathon.executors.CreateAgentRequestExecutor.java

License:Apache License

@Override
public GoPluginApiResponse execute() throws Exception {
    /*/*from  w  w w.j  a  v a  2s . co m*/
    The logic here is that the go server has a list of agents, but
    not a definitive view of which of those agents is actually
    running.  This means that this plugin is sent a createAgentRequest
    for every matching job being scheduled.
            
    The housekeeping we do to prevent over-creating new instances is to
    get a list of agents from the go server, find idle ones in the list,
    and match to the corresponding instance running on marathon.  If the
    instance running on marathon would satisfy the request, we do not create
    a new instance.
            
    In the case where we might get multiple createAgentRequests in a short
    period of time, we mark the instance as recently matched so it is not
    eligible to match for subsequent requests.
            
    This isn't perfect - we might mark one and then the job actually gets
    scheduled to another agent.  In the long term, the go agents will use
    web sockets, the go server will know which ones are still running, and
    we can drop this logic here.
     */

    boolean agentMatch = false;
    for (Agent agent : pluginRequest.listAgents().agents()) {
        if (!agentIdle(agent)) {
            continue;
        }
        MarathonInstance instance = (MarathonInstance) agentInstances.find(agent.elasticAgentId());
        if (instance == null) {
            continue;
        }
        if (!propertiesMatch(instance.properties(), request.properties())) {
            continue;
        }
        // Recently matched to an outstanding task
        if (instance.getLastMatched().isAfter(new DateTime().minus(new Period("PT30S")))) {
            continue;
        }
        agentMatch = true;
        instance.setLastMatched(new DateTime());
        break;
    }
    if (!agentMatch) {
        agentInstances.create(request, pluginRequest.getPluginSettings());
    }
    return new DefaultGoPluginApiResponse(200);
}

From source file:cd.go.contrib.elasticagents.marathon.MarathonAgentInstances.java

License:Apache License

@Override
public void refreshAll(PluginRequest pluginRequest) throws Exception {
    if (refreshed) {
        if (refreshedTime == null) {
            setRefreshed(false);//www. j a  va  2 s  .c  o  m
        } else {
            if (refreshedTime.isBefore(new DateTime().minus(new Period("PT10M")))) {
                setRefreshed(false);
            }
        }
    }
    if (!refreshed) {
        PluginSettings settings = pluginRequest.getPluginSettings();
        List<MarathonInstance> marathonInstanceList = marathon(settings).getGoAgents(settings);
        for (MarathonInstance instance : marathonInstanceList) {
            register(instance);
        }
        LOG.debug("Instances found: " + marathonInstanceList.toString());
        setRefreshedTime(new DateTime());
        setRefreshed(true);
    }
}

From source file:cd.go.contrib.elasticagents.marathon.MarathonInstance.java

License:Apache License

MarathonInstance(String name, DateTime createdAt, String environment, String goServerUrl, String marathonPrefix,
        String image, Double memory, Double cpus, String command, String user, String constraints, String uris,
        String volumes, Map<String, String> autoRegisterProperties) {
    this.name = name;
    this.createdAt = createdAt;
    this.environment = environment;
    this.goServerUrl = goServerUrl;
    this.marathonPrefix = marathonPrefix;
    this.image = image;
    this.memory = memory;
    this.cpus = cpus;
    this.command = command;
    this.user = user;
    this.constraints = constraints;
    this.uris = uris;
    this.volumes = volumes;
    this.autoRegisterProperties = autoRegisterProperties;
    this.app = buildApp();
    this.lastMatched = new DateTime();
}

From source file:cd.go.contrib.elasticagents.marathon.MarathonInstance.java

License:Apache License

public static MarathonInstance instanceFromApp(App app, PluginSettings settings) {
    Map<String, String> autoRegisterProperties = new HashMap<>();
    autoRegisterProperties.put("GO_EA_AUTO_REGISTER_KEY", app.getEnv().get("GO_EA_AUTO_REGISTER_KEY"));
    autoRegisterProperties.put("GO_EA_AUTO_REGISTER_ENVIRONMENT",
            app.getEnv().get("GO_EA_AUTO_REGISTER_ENVIRONMENT"));
    autoRegisterProperties.put("GO_EA_AUTO_REGISTER_ELASTIC_AGENT_ID",
            app.getEnv().get("GO_EA_AUTO_REGISTER_ELASTIC_AGENT_ID"));
    autoRegisterProperties.put("GO_EA_AUTO_REGISTER_ELASTIC_PLUGIN_ID",
            app.getEnv().get("GO_EA_AUTO_REGISTER_ELASTIC_PLUGIN_ID"));

    DateTime createdTime = new DateTime();

    if (app.getTasks() != null) {
        if (app.getTasks().size() > 0) {
            createdTime = new DateTime(Iterables.get(app.getTasks(), 0).getStagedAt());
        }//from  w w  w .  j  a v  a2 s. c  o m
    }

    Gson gson = new Gson();
    List<String> constraintList = new ArrayList<>();

    for (List<String> constraint : app.getConstraints()) {
        constraintList.add(gson.toJson(constraint));
    }
    String constraints = String.join("\n", constraintList);

    String uris = app.getUris() == null ? "" : String.join("\n", app.getUris());

    List<String> volumes = new ArrayList<>();
    if (app.getContainer().getVolumes() != null) {
        for (Volume volume : app.getContainer().getVolumes()) {
            volumes.add(volume.getContainerPath() + ":" + volume.getHostPath() + ":" + volume.getMode());
        }
    }
    String vols = String.join("\n", volumes);

    return new MarathonInstance(app.getId().substring(settings.getMarathonPrefix().length()), createdTime,
            app.getEnv().get("GO_EA_AUTO_REGISTER_ENVIRONMENT"), settings.getGoServerUrl(),
            settings.getMarathonPrefix(), app.getContainer().getDocker().getImage(), app.getMem(),
            app.getCpus(), app.getCmd(), app.getEnv().get("GO_EA_USER"), constraints, uris, vols,
            autoRegisterProperties);
}

From source file:cd.go.contrib.elasticagents.marathon.MarathonInstance.java

License:Apache License

public static MarathonInstance create(CreateAgentRequest request, PluginSettings settings,
        marathonClient marathon) {//from  ww w .j a va  2 s. c  o m
    String name = UUID.randomUUID().toString();
    MarathonInstance marathonInstance = new MarathonInstance(name, new DateTime(), request.environment(),
            settings.getGoServerUrl(), settings.getMarathonPrefix(), request.properties().get("Image"),
            Double.valueOf(Size.parse(request.properties().get("Memory")).toMegabytes()),
            Double.valueOf(request.properties().get("CPUs")), request.properties().get("Command"),
            request.properties().get("User"), request.properties().get("Constraints"),
            request.properties().get("URIs"), request.properties().get("Volumes"),
            request.autoregisterPropertiesAsEnvironmentVars(name));

    LOG.info("Creating instance " + marathonInstance.app.getId());
    return marathon.requestGoAgent(marathonInstance);
}

From source file:ch.emad.business.schuetu.zeit.Zeitgeber.java

License:Apache License

public synchronized void startClock(final DateTime richtigeZeit, final DateTime spielzeit,
        final Integer verschnellerung) {

    if (verschnellerung != null) {
        this.verschnellerungsfaktor = verschnellerung;
    } else {//from  w w w .j a  v  a  2  s . c o  m
        this.verschnellerungsfaktor = 1;
    }

    if (richtigeZeit != null) {
        zeitJetzt = richtigeZeit.getMillis();
    } else {
        zeitJetzt = new DateTime().getMillis();
    }

    if (spielzeit != null) {
        abweichungZuSpielzeit = spielzeit.getMillis() - this.zeitJetzt;
    } else {
        abweichungZuSpielzeit = 0;
    }

    this.startClock();
    this.startGame();

    Zeitgeber.LOG.info("zeitgeber: startClock() gestartet mit abweichung zur spielzeit: "
            + this.abweichungZuSpielzeit / 1000 + " sekunden");

}

From source file:ch.emad.model.schuetu.model.SpielEinstellungen.java

License:Apache License

public SpielEinstellungen() {
    DateTime date = new DateTime();
    date.withDate(2013, 6, 8);
    starttag = date.toDate();
}

From source file:ch.icclab.cyclops.persistence.orm.InstanceORM.java

License:Open Source License

/**
 * Current time/*from  w w w.  j  a v  a 2  s.com*/
 * @return string
 */
private String getCurrentTime() {
    DateTimeFormatter fmt = DateTimeFormat.forPattern("H:m:s.S d/MMM/y");
    return fmt.print(new DateTime());
}