// This simple scheduler implementation only decides what to do at
// creation and when to shutdown (with lockdown of web services start
// and shutdown operations).
InstanceResource resource = null;
// In the case of a slot obtained in a delayed manner (e.g. using
// the workspace-pilot and/or coscheduled), we cannot act on
// STATE_FIRST_LEGAL unless this.slotReserved is called (where
// stop is !null).
// In the future, stop time should not be overloaded like this, make
// a more explicit parameter.
boolean noActivateSituation = false;
boolean populateAndSchedule = false;
if (state == WorkspaceConstants.STATE_FIRST_LEGAL) {
if (this.slotManager.isBestEffort() && stop == null) {
noActivateSituation = true;
} else if (this.slotManager.isBestEffort()) {
populateAndSchedule = true;
} else {
resource = this.fetchResource(id, state);
if (resource == null) {
return;
}
if (resource.getEnsembleId() != null) {
if (stop == null) {
noActivateSituation = true;
} else {
populateAndSchedule = true;
}
}
}
}
if (state == WorkspaceConstants.STATE_FIRST_LEGAL) {
this.creationPending.notpending(id);
if (noActivateSituation) {
return;
}
}
// Since it is immediate, nothing needs to be decided.
if (state == WorkspaceConstants.STATE_FIRST_LEGAL) {
if (resource == null) {
resource = this.fetchResource(id, state);
if (resource == null) {
return;
}
}
if (populateAndSchedule) {
// note that in the pilot case running time duration currently
// equals requested running time, leaving no time for
// unpropagation (need B scheduler), client will need to call
// shutdown + ready-for-transport to get unpropagation
this.db.scheduleTasks(id, stop);
if (hostname == null) {
logger.error(Lager.id(id) + "scheduler received " +
"slot-reserved notification without a hostname");
return;
} else {
resource.newHostname(hostname);
}
if (start == null) {
logger.error(Lager.id(id) + "scheduler received " +
"slot-reserved notification without a start time");
return;
} else {
resource.newStartTime(start);
}
if (stop == null) {
// this is actually impossible to reach, leaving in
// for future developers
logger.error(Lager.id(id) + "scheduler received " +
"slot-reserved notification without a stop time");
return;
} else {
resource.newStopTime(stop);
}
}
resource.setOpsEnabled(true);
try {
resource.activate();
this.sweeper.scheduleSweeper();
} catch (ManageException e) {
logger.error("", e);
}
}
/* Once transport-readying is hit for any reason, no turning back */
else if (state == WorkspaceConstants.STATE_READYING_FOR_TRANSPORT) {
try {
resource = this.home.find(id);
} catch (DoesNotExistException e) {
logger.error("scheduler received state notification (" +
this.dataConvert.stateName(state) + ") about " +
Lager.id(id) + ", but it seems to be gone now", e);
return;
}
// find will not return null
resource.setOpsEnabled(false);
try {
this.db.markShutdown(id);
} catch (WorkspaceDatabaseException e) {
logger.error("", e);
}