final String targetId = String.format("target-%s", Long.toHexString(System.nanoTime()));
List<Event> events = new ArrayList<Event>();
events.add(new Event(targetId, 1, 1, 1, AuditEvent.FRAMEWORK_STARTED));
// fill auditlog; no install data
m_auditLogStore.put(events);
runAndWaitForEvent(new Callable<Void>() {
public Void call() throws Exception {
m_statefulTargetRepository.refresh();
return null;
}
}, false, StatefulTargetObject.TOPIC_AUDITEVENTS_CHANGED, StatefulTargetObject.TOPIC_ADDED);
StatefulTargetObject sgo = findStatefulTarget(targetId);
assertNotNull("Expected new target object to become available!", sgo);
assertEquals("We expect our object's provisioning state to be Idle;", ProvisioningState.Idle, sgo.getProvisioningState());
// fill auditlog with complete-data
events = new ArrayList<Event>();
Map<String, String> props = new HashMap<String, String>();
props.put(AuditEvent.KEY_NAME, "mypackage");
props.put(AuditEvent.KEY_VERSION, "123");
events.add(new Event(targetId, 1, 2, 2, AuditEvent.DEPLOYMENTCONTROL_INSTALL, props));
m_auditLogStore.put(events);
runAndWaitForEvent(new Callable<Void>() {
public Void call() throws Exception {
m_statefulTargetRepository.refresh();
return null;
}
}, false, StatefulTargetObject.TOPIC_STATUS_CHANGED, StatefulTargetObject.TOPIC_AUDITEVENTS_CHANGED);
assertEquals("Our last install version should be 123;", "123", sgo.getLastInstallVersion());
assertEquals("We expect our object's provisioning state to be InProgress;", ProvisioningState.InProgress, sgo.getProvisioningState());
// fill auditlog with install data
events = new ArrayList<Event>();
props = new HashMap<String, String>();
props.put(AuditEvent.KEY_NAME, "mypackage");
props.put(AuditEvent.KEY_VERSION, "123");
props.put(AuditEvent.KEY_SUCCESS, "false");
events.add(new Event(targetId, 1, 3, 3, AuditEvent.DEPLOYMENTADMIN_COMPLETE, props));
m_auditLogStore.put(events);
runAndWaitForEvent(new Callable<Void>() {
public Void call() throws Exception {
m_statefulTargetRepository.refresh();
return null;
}
}, false, StatefulTargetObject.TOPIC_AUDITEVENTS_CHANGED, StatefulTargetObject.TOPIC_STATUS_CHANGED);
assertEquals("Our last install version should be 123;", "123", sgo.getLastInstallVersion());
assertEquals("We expect our object's provisioning state to be Failed;", ProvisioningState.Failed, sgo.getProvisioningState());
assertFalse("Our last install was not successful, but according to the sgo it was.", sgo.getLastInstallSuccess());
sgo.acknowledgeInstallVersion("123");
assertEquals("We expect our object's provisioning state to be Idle;", ProvisioningState.Idle, sgo.getProvisioningState());
// add another install event.
events = new ArrayList<Event>();
props = new HashMap<String, String>();
props.put(AuditEvent.KEY_NAME, "mypackage");
props.put(AuditEvent.KEY_VERSION, "124");
events.add(new Event(targetId, 1, 4, 4, AuditEvent.DEPLOYMENTCONTROL_INSTALL, props));
m_auditLogStore.put(events);
runAndWaitForEvent(new Callable<Void>() {
public Void call() throws Exception {
m_statefulTargetRepository.refresh();
return null;
}
}, false, StatefulTargetObject.TOPIC_AUDITEVENTS_CHANGED, StatefulTargetObject.TOPIC_STATUS_CHANGED);
assertEquals("Our last install version should be 124;", "124", sgo.getLastInstallVersion());
assertEquals("We expect our object's provisioning state to be InProgress;", ProvisioningState.InProgress, sgo.getProvisioningState());
// fill auditlog with install data
events = new ArrayList<Event>();
props = new HashMap<String, String>();
props.put(AuditEvent.KEY_NAME, "mypackage");
props.put(AuditEvent.KEY_VERSION, "124");
props.put(AuditEvent.KEY_SUCCESS, "true");
events.add(new Event(targetId, 1, 5, 5, AuditEvent.DEPLOYMENTADMIN_COMPLETE, props));
m_auditLogStore.put(events);
runAndWaitForEvent(new Callable<Void>() {
public Void call() throws Exception {