Package org.apache.ace.client.repository.stateful

Examples of org.apache.ace.client.repository.stateful.StatefulTargetObject


   
    private final ExecutorService m_executor = Executors.newCachedThreadPool();
   
    public Panel create(Map<String, Object> context) {
        NamedObject namedObject = (NamedObject) context.get("object");
        StatefulTargetObject target = (StatefulTargetObject) namedObject.getObject();
        return new NodePanel(this, target.getID());
    }
View Full Code Here


        public RepositoryObject lookup(Object value) {
            RepositoryObject object = null;
            if (value instanceof String) {
                object = m_repository.get((String) value);
                if (object instanceof StatefulTargetObject) {
                    StatefulTargetObject sgo = (StatefulTargetObject) object;
                    if (sgo.isRegistered()) {
                        object = sgo.getTargetObject();
                    }
                    else {
                        object = null;
                    }
                }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    @Override
    protected WorkingState getWorkingState(RepositoryObject object) {
        final StatefulTargetObject statefulTarget = (StatefulTargetObject) object;
        if (statefulTarget.isRegistered()) {
            return super.getWorkingState(statefulTarget.getTargetObject());
        }
        return WorkingState.Unchanged;
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    protected void handleEvent(String topic, RepositoryObject entity, org.osgi.service.event.Event event) {
        StatefulTargetObject statefulTarget = asStatefulTargetObject(entity);
        if (StatefulTargetObject.TOPIC_ADDED.equals(topic)) {
            add(statefulTarget);
        }
        if (StatefulTargetObject.TOPIC_REMOVED.equals(topic)) {
            remove(statefulTarget);
View Full Code Here

       
        final Map<String, String> attr = new HashMap<String, String>();
    attr.put(TargetObject.KEY_ID, targetId);
   
    final Map<String, String> tags = new HashMap<String, String>();
    final StatefulTargetObject sgo = runAndWaitForEvent(new Callable<StatefulTargetObject>() {
        public StatefulTargetObject call() throws Exception {
            return m_statefulTargetRepository.preregister(attr, tags);
        }
    }, false, TargetObject.TOPIC_ADDED, TOPIC_ADDED);
   
    assertTrue("Without any deployment versions, and no information in the shop, we should not need to approve.", !sgo.needsApprove());
    assertEquals("We expect the registration state to be Registered;", RegistrationState.Registered, sgo.getRegistrationState());
    assertEquals("We expect the registration state to be New;", StoreState.New, sgo.getStoreState());
    assertEquals(UNKNOWN_VERSION, sgo.getCurrentVersion());
   
    final ArtifactObject b11 = createBasicBundleObject("bundle1", "1", null);
   
    FeatureObject g1 = createBasicFeatureObject("feature1");
    FeatureObject g2 = createBasicFeatureObject("feature2"); // note that this feature is not associated to a bundle.
   
    createDynamicBundle2FeatureAssociation(b11, g1);
   
    final DistributionObject l1 = createBasicDistributionObject("distribution1");
   
    m_feature2distributionRepository.create(g1, l1);
    m_feature2distributionRepository.create(g2, l1);
   
    runAndWaitForEvent(new Callable<Distribution2TargetAssociation>() {
        public Distribution2TargetAssociation call() throws Exception {
            return m_distribution2targetRepository.create(l1, sgo.getTargetObject());
        }
    }, false, Distribution2TargetAssociation.TOPIC_ADDED, TOPIC_STATUS_CHANGED);
   
    assertTrue("We added information that influences our target, so we should need to approve it.", sgo.needsApprove());
    assertEquals("We expect the registration state to be Registered;", RegistrationState.Registered, sgo.getRegistrationState());
    assertEquals("We expect the registration state to be Unapproved;", StoreState.Unapproved, sgo.getStoreState());
    assertEquals("According to the shop, this target needs 1 bundle", 1, sgo.getArtifactsFromShop().length);
    assertEquals("According to the deployment, this target needs 0 bundles", 0, sgo.getArtifactsFromDeployment().length);
    assertEquals(UNKNOWN_VERSION, sgo.getCurrentVersion());
   
    runAndWaitForEvent(new Callable<Object>() {
        public Object call() throws Exception {
            createBasicDeploymentVersionObject(targetId, "1", b11);
            return null;
        }
    }, false, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);
   
    assertFalse("We manually created a deployment version that reflects the shop, so no approval should be necessary.", sgo.needsApprove());
    assertEquals("We expect the registration state to be Registered;", RegistrationState.Registered, sgo.getRegistrationState());
    assertEquals("We expect the registration state to be Approved;", StoreState.Approved, sgo.getStoreState());
    assertEquals("According to the shop, this target needs 1 bundle;", 1, sgo.getArtifactsFromShop().length);
    assertEquals("According to the deployment, this target needs 1 bundle;", 1, sgo.getArtifactsFromDeployment().length);
   
    runAndWaitForEvent(new Callable<ArtifactObject>() {
        public ArtifactObject call() throws Exception {
            return createBasicBundleObject("bundle1", "2", null);
        }
    }, false, ArtifactObject.TOPIC_ADDED, Artifact2FeatureAssociation.TOPIC_CHANGED, TOPIC_STATUS_CHANGED);
   
    assertTrue("We added a new version of a bundle that is used by the target, so approval should be necessary.", sgo.needsApprove());
    assertEquals("We expect the registration state to be Registered;", RegistrationState.Registered, sgo.getRegistrationState());
    assertEquals("We expect the registration state to be Unapproved;", StoreState.Unapproved, sgo.getStoreState());
    assertEquals("According to the shop, this target needs 1 bundle", 1, sgo.getArtifactsFromShop().length);
    assertEquals("The shop should tell use we need bundle URL 'bundle1-2';", "http://bundle1-2", sgo.getArtifactsFromShop()[0].getURL());
    assertEquals("According to the deployment, this target needs 1 bundle", 1, sgo.getArtifactsFromDeployment().length);
    assertEquals("The deployment should tell use we need bundle URL 'bundle1-1';", "http://bundle1-1", sgo.getArtifactsFromDeployment()[0].getUrl());
    assertEquals("1", sgo.getCurrentVersion());
   
    final String newVersion = runAndWaitForEvent(new Callable<String>() {
        public String call() throws Exception {
            return sgo.approve();
        }
    }, false, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);
   
    assertFalse("Immediately after approval, no approval is necessary.", sgo.needsApprove());
    assertEquals("We expect the registration state to be Registered;", RegistrationState.Registered, sgo.getRegistrationState());
    assertEquals("We expect the registration state to be Approved;", StoreState.Approved, sgo.getStoreState());
    assertEquals("According to the shop, this target needs 1 bundle", 1, sgo.getArtifactsFromShop().length);
    assertEquals("The shop should tell use we need bundle URL 'bundle1-2';", "http://bundle1-2", sgo.getArtifactsFromShop()[0].getURL());
    assertEquals("According to the deployment, this target needs 1 bundle", 1, sgo.getArtifactsFromDeployment().length);
    assertEquals("The deployment should tell use we need bundle URL 'bundle1-2';", "http://bundle1-2", sgo.getArtifactsFromDeployment()[0].getUrl());
    assertEquals( "We expect two deployment versions;", 2, m_deploymentVersionRepository.get().size());
    assertEquals(newVersion, sgo.getCurrentVersion());
   
    // clean up this object ourselves; we cannot rely on cleanUp() in this case.
    runAndWaitForEvent(new Callable<Object>() {
        public Object call() throws Exception {
            m_statefulTargetRepository.unregister(targetId);
            return null;
        }
    }, false, TargetObject.TOPIC_REMOVED, TOPIC_REMOVED);

     StatefulTargetObject target = findStatefulTarget(targetId);
     assertNull("Target should be removed?!", target);
   
    cleanUp();
    }
View Full Code Here

        // preregister target
    final Map<String, String> attr = new HashMap<String, String>();
    attr.put(TargetObject.KEY_ID, "myNewTarget3");
    final Map<String, String> tags = new HashMap<String, String>();
   
    final StatefulTargetObject sgo1 = runAndWaitForEvent(new Callable<StatefulTargetObject>() {
        public StatefulTargetObject call() throws Exception {
            return m_statefulTargetRepository.preregister(attr, tags);
        }
    }, false, TargetObject.TOPIC_ADDED, TOPIC_ADDED);
   
    // do checks
    assertTrue("We just preregistered a target, so it should be registered.", sgo1.isRegistered());
   
    // add auditlog data
    List<LogEvent> events = new ArrayList<LogEvent>();
    Properties props = new Properties();
    events.add(new LogEvent("myNewTarget3", 1, 1, 1, AuditEvent.FRAMEWORK_STARTED, props));
    m_auditLogStore.put(events);
    m_statefulTargetRepository.refresh();
   
    // do checks
    assertTrue("Adding auditlog data for a target does not influence its isRegistered().", sgo1.isRegistered());
    try {
        sgo1.getTargetObject();
    }
    catch (IllegalStateException ise) {
        assertTrue("We should be able to get sgo1's targetObject.", false);
    }
   
    // add auditlog data for other target
    events = new ArrayList<LogEvent>();
    props = new Properties();
    events.add(new LogEvent("myNewTarget4", 1, 1, 1, AuditEvent.FRAMEWORK_STARTED, props));
    m_auditLogStore.put(events);
    runAndWaitForEvent(new Callable<Object>() {
        public Object call() throws Exception {
            m_statefulTargetRepository.refresh();
            return false;
        }
    }, false, TOPIC_ADDED);
    final StatefulTargetObject sgo2 = findStatefulTarget("myNewTarget4");
   
    // do checks
    assertTrue("Adding auditlog data for a target does not influence its isRegistered().", sgo1.isRegistered());
    try {
        sgo1.getTargetObject();
    }
    catch (IllegalStateException ise) {
        assertTrue("We should be able to get sgo1's targetObject.", false);
    }
    assertTrue("sgo2 is only found in the auditlog, so it cannot be in registered.", !sgo2.isRegistered());
    try {
        sgo2.getTargetObject();
        assertTrue("We should not be able to get sgo2's targetObject.", false);
    }
    catch (IllegalStateException ise) {
        // expected
    }
   
    // remove original target
    runAndWaitForEvent(new Callable<Object>() {
        public Object call() throws Exception {
            m_statefulTargetRepository.unregister(sgo1.getID());
            return null;
        }
    }, false, TargetObject.TOPIC_REMOVED, TOPIC_STATUS_CHANGED);
   
    // do checks
    assertTrue("sgo1 is now only found in the auditlog, so it cannot be registered.", !sgo1.isRegistered());
    try {
        sgo1.getTargetObject();
        assertTrue("We should not be able to get sgo1's targetObject.", false);
    }
    catch (IllegalStateException ise) {
        // expected
    }
    assertTrue("sgo2 is only found in the auditlog, so it cannot be in registered.", !sgo2.isRegistered());
    try {
        sgo2.getTargetObject();
        assertTrue("We should not be able to get sgo2's targetObject.", false);
    }
    catch (IllegalStateException ise) {
        // expected
    }
   
    // register second target
    runAndWaitForEvent(new Callable<Object>() {
        public Object call() throws Exception {
            sgo2.register();
            return null;
        }
    }, false, TargetObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);
   
    // do checks
    assertTrue("sgo1 is now only found in the auditlog, so it cannot be in registered.", !sgo1.isRegistered());
    try {
        sgo1.getTargetObject();
        assertTrue("We should not be able to get sgo1's targetObject.", false);
    }
    catch (IllegalStateException ise) {
        // expected
    }
    assertTrue("sgo2 has been registered.", sgo2.isRegistered());
    try {
        sgo2.getTargetObject();
    }
    catch (IllegalStateException ise) {
        assertTrue("We should be able to get sgo2's targetObject.", false);
    }
   
View Full Code Here

        // preregister gateway
    final Map<String, String> attr = new HashMap<String, String>();
    attr.put(TargetObject.KEY_ID, "myNewGatewayA");
    final Map<String, String> tags = new HashMap<String, String>();
   
    final StatefulTargetObject sgo1 = runAndWaitForEvent(new Callable<StatefulTargetObject>() {
        public StatefulTargetObject call() throws Exception {
            return m_statefulTargetRepository.preregister(attr, tags);
        }
    }, false, TargetObject.TOPIC_ADDED, TOPIC_ADDED);
   
    // do checks
    assertTrue("We just preregistered a gateway, so it should be registered.", sgo1.isRegistered());
   
    // add auditlog data
    List<LogEvent> events = new ArrayList<LogEvent>();
    Properties props = new Properties();
    events.add(new LogEvent("myNewGatewayA", 1, 1, 1, AuditEvent.FRAMEWORK_STARTED, props));
    m_auditLogStore.put(events);
    m_statefulTargetRepository.refresh();
   
    // do checks
    assertTrue("Adding auditlog data for a gateway does not influence its isRegistered().", sgo1.isRegistered());
    try {
        sgo1.getTargetObject();
    }
    catch (IllegalStateException ise) {
        assertTrue("We should be able to get sgo1's gatewayObject.", false);
    }
    // add auditlog data for other gateway
    events = new ArrayList<LogEvent>();
    props = new Properties();
    events.add(new LogEvent("myNewGatewayB", 1, 1, 1, AuditEvent.FRAMEWORK_STARTED, props));
    m_auditLogStore.put(events);
    runAndWaitForEvent(new Callable<Object>() {
        public Object call() throws Exception {
            m_statefulTargetRepository.refresh();
            return false;
        }
    }, false, TOPIC_ADDED);
    final StatefulTargetObject sgo2 = findStatefulTarget("myNewGatewayB");
   
    // do checks
    assertTrue("Adding auditlog data for a gateway does not influence its isRegistered().", sgo1.isRegistered());
    try {
        sgo1.getTargetObject();
    }
    catch (IllegalStateException ise) {
        assertTrue("We should be able to get sgo1's gatewayObject.", false);
    }
    assertTrue("sgo2 is only found in the auditlog, so it cannot be in registered.", !sgo2.isRegistered());
    try {
        sgo2.getTargetObject();
        assertTrue("We should not be able to get sgo2's gatewayObject.", false);
    }
    catch (IllegalStateException ise) {
        // expected
    }
    // remove original gateway
    runAndWaitForEvent(new Callable<Object>() {
        public Object call() throws Exception {
            m_statefulTargetRepository.remove(sgo1);
            return null;
        }
    }, false, TargetObject.TOPIC_REMOVED, TOPIC_REMOVED);
   
    // do checks
    assertTrue("sgo1 is now only found in the auditlog, so it cannot be registered.", !sgo1.isRegistered());
    try {
        sgo1.getTargetObject();
        assertTrue("We should not be able to get sgo1's gatewayObject.", false);
    }
    catch (IllegalStateException ise) {
        // expected
    }
   
    assertTrue("sgo2 is only found in the auditlog, so it cannot be in registered.", !sgo2.isRegistered());
    try {
        sgo2.getTargetObject();
        assertTrue("We should not be able to get sgo2's gatewayObject.", false);
    }
    catch (IllegalStateException ise) {
        // expected
    }
   
    // register second gateway
    runAndWaitForEvent(new Callable<Object>() {
        public Object call() throws Exception {
            sgo2.register();
            return null;
        }
    }, false, TargetObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);
   
    // do checks
    assertTrue("sgo1 is now only found in the auditlog, so it cannot be in registered.", !sgo1.isRegistered());
    try {
        sgo1.getTargetObject();
        assertTrue("We should not be able to get sgo1's gatewayObject.", false);
    }
    catch (IllegalStateException ise) {
        // expected
    }
    assertTrue("sgo2 has been registered.", sgo2.isRegistered());
    try {
        sgo2.getTargetObject();
    }
    catch (IllegalStateException ise) {
        assertTrue("We should be able to get sgo2's gatewayObject.", false);
    }
   
View Full Code Here

          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<LogEvent>();
    props = new Properties();
    props.put(AuditEvent.KEY_NAME, "mypackage");
    props.put(AuditEvent.KEY_VERSION, "123");
    events.add(new LogEvent(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<LogEvent>();
    props = new Properties();
    props.put(AuditEvent.KEY_NAME, "mypackage");
    props.put(AuditEvent.KEY_VERSION, "123");
    props.put(AuditEvent.KEY_SUCCESS, "false");
    events.add(new LogEvent(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<LogEvent>();
    props = new Properties();
    props.put(AuditEvent.KEY_NAME, "mypackage");
    props.put(AuditEvent.KEY_VERSION, "124");
    events.add(new LogEvent(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<LogEvent>();
    props = new Properties();
    props.put(AuditEvent.KEY_NAME, "mypackage");
    props.put(AuditEvent.KEY_VERSION, "124");
    props.put(AuditEvent.KEY_SUCCESS, "true");
    events.add(new LogEvent(targetId, 1, 5, 5, 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 124;", "124", sgo.getLastInstallVersion());
    assertEquals("We expect our object's provisioning state to be OK;", ProvisioningState.OK, sgo.getProvisioningState());
    assertTrue("Our last install was successful, but according to the sgo it was not.", sgo.getLastInstallSuccess());
   
    sgo.acknowledgeInstallVersion("124");
   
    assertEquals("We expect our object's provisioning state to be Idle;", ProvisioningState.Idle, sgo.getProvisioningState());
    }
View Full Code Here

    }
    catch (UnsupportedOperationException uoe) {
        // expected
    }
   
    final StatefulTargetObject sgo = runAndWaitForEvent(new Callable<StatefulTargetObject>() {
        public StatefulTargetObject call() throws Exception {
            return m_statefulTargetRepository.preregister(attr, tags);
        }
    }, false, TargetObject.TOPIC_ADDED, TOPIC_ADDED);
   
View Full Code Here

    final Map<String, String> attr = new HashMap<String, String>();
    attr.put(TargetObject.KEY_ID, targetId);
    attr.put(TargetObject.KEY_AUTO_APPROVE, String.valueOf(true));
    final Map<String, String> tags = new HashMap<String, String>();
   
    final StatefulTargetObject sgo = runAndWaitForEvent(new Callable<StatefulTargetObject>() {
        public StatefulTargetObject call() throws Exception {
            return m_statefulTargetRepository.preregister(attr, tags);
        }
    }, false, TargetObject.TOPIC_ADDED, TOPIC_ADDED);
   
    assertNotNull("We expect to found our new target in the repository!", findStatefulTarget(targetId));
   
    assertTrue("The target should have auto approved value: true but got: false.", sgo.getAutoApprove());
   
    sgo.setAutoApprove(false);
   
    assertFalse("The target should have auto approved value: false but got: true.", sgo.getAutoApprove());
   
    // clean up
    runAndWaitForEvent(new Callable<Object>() {
        public Object call() throws Exception {
            m_statefulTargetRepository.unregister(targetId);
View Full Code Here

TOP

Related Classes of org.apache.ace.client.repository.stateful.StatefulTargetObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.