try {
final VM vm = manager.getInstance(mgrInstanceID);
if (vm != null) {
final State state = vm.getState();
if (state != null) {
final String mgrState = state.getState();
final InstanceStateType ist = new InstanceStateType();
ist.setName(StateMap.managerStringToElasticString(mgrState));
ist.setCode(StateMap.managerStringToElasticInt(mgrState));
currentStates[i] = ist;
}
}
} catch (DoesNotExistException e) {
currentStates[i] = null;
} catch (ManageException e) {
currentStates[i] = null;
logger.error(e.getMessage());
}
}
for (int i = 0; i < managerInstances.length; i++) {
if (currentStates[i] == null) {
continue;
}
final String mgrID = managerInstances[i];
try {
manager.trash(mgrID, Manager.INSTANCE, caller);
} catch (DoesNotExistException e) {
// do nothing, already accomplished
} catch (ManageException e) {
if (logger.isDebugEnabled()) {
logger.error(e.getMessage(), e);
} else {
logger.error(e.getMessage());
}
}
}
final InstanceStateType terminated = new InstanceStateType();
terminated.setCode(StateMap.STATE_TERMINATED.intValue());
terminated.setName(StateMap.STATE_TERMINATED_STR);
final InstanceStateType[] newStates =
new InstanceStateType[managerInstances.length];
for (int i = 0; i < managerInstances.length; i++) {
if (currentStates[i] == null) {
continue;
}
final String mgrInstanceID = managerInstances[i];
try {
final VM vm = manager.getInstance(mgrInstanceID);
if (vm != null) {
final State state = vm.getState();
if (state != null) {
final String mgrState = state.getState();
final InstanceStateType ist = new InstanceStateType();
ist.setName(StateMap.managerStringToElasticString(mgrState));
ist.setCode(StateMap.managerStringToElasticInt(mgrState));
newStates[i] = ist;
}