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

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


        }
        else if (Workspace.TARGET.equals(entityType) && ACTION_REGISTER.equals(action)) {
            resp.getWriter().println(m_gson.toJson(((StatefulTargetObject) repositoryObject).getRegistrationState()));
        }
        else if (Workspace.TARGET.equals(entityType) && ACTION_AUDITEVENTS.equals(action)) {
            StatefulTargetObject target = (StatefulTargetObject) repositoryObject;
            List<LogEvent> events = target.getAuditEvents();

            String startValue = req.getParameter("start");
            String maxValue = req.getParameter("max");

            int start = (startValue == null) ? 0 : Integer.parseInt(startValue);
View Full Code Here


            resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Repository object of type " + entityType + " and identity " + entityId + " not found.");
            return;
        }

        if (Workspace.TARGET.equals(entityType) && ACTION_APPROVE.equals(action)) {
            StatefulTargetObject sto = workspace.approveTarget((StatefulTargetObject) repositoryObject);

            // Respond with the current store state...
            resp.getWriter().println(m_gson.toJson(sto.getStoreState()));
        }
        else if (Workspace.TARGET.equals(entityType) && ACTION_REGISTER.equals(action)) {
            StatefulTargetObject sto = workspace.registerTarget((StatefulTargetObject) repositoryObject);
            if (sto == null) {
                resp.sendError(HttpServletResponse.SC_CONFLICT, "Target already registered: " + entityId);
            }
            else {
                // Respond with the current registration state...
                resp.getWriter().println(m_gson.toJson(sto.getRegistrationState()));
            }
        }
        else {
            resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Unknown action for " + entityType);
        }
View Full Code Here

        if (!(object instanceof StatefulTargetObject)) {
            result.addComponent(new Label("This target is not a stateful gateway object."));
            return result;
        }

        final StatefulTargetObject target = (StatefulTargetObject) object;

        final CheckBox registerCB = new CheckBox("Registered?");
        registerCB.setImmediate(true);
        registerCB.setEnabled(!target.isRegistered());
        registerCB.setValue(Boolean.valueOf(target.isRegistered()));

        result.addComponent(registerCB);

        final CheckBox autoApproveCB = new CheckBox("Auto approve?");
        autoApproveCB.setImmediate(true);
        autoApproveCB.setEnabled(target.isRegistered());
        autoApproveCB.setValue(Boolean.valueOf(target.getAutoApprove()));

        result.addComponent(autoApproveCB);


        final Button approveButton = new Button("Approve changes");
        approveButton.setImmediate(true);
        approveButton.setEnabled(target.needsApprove());

        result.addComponent(approveButton);
       
        // Add a spacer that fill the remainder of the available space...
        result.addComponent(new Label(" "));
        result.setRowExpandRatio(3, 1.0f);
       
        // Add all listeners...
        registerCB.addListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                if (event.getButton().booleanValue()) {
                    target.register();
                    registerCB.setEnabled(!target.isRegistered());
                    autoApproveCB.setEnabled(target.isRegistered());
                }
            }
        });
        autoApproveCB.addListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                target.setAutoApprove(event.getButton().booleanValue());
                approveButton.setEnabled(target.needsApprove());
            }
        });
        approveButton.addListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                target.approve();
                approveButton.setEnabled(target.needsApprove());
            }
        });

        return result;
    }
View Full Code Here

                createBasicTargetObject("testAutoApproveTarget");
                return null;
            }
        }, false, TargetObject.TOPIC_ADDED, TOPIC_ADDED);

        final StatefulTargetObject sgo =
            m_statefulTargetRepository.get(
                m_bundleContext.createFilter("(" + TargetObject.KEY_ID + "=" + "testAutoApproveTarget)")).get(0);

        // Set up some deployment information for the target.
        final FeatureObject g = runAndWaitForEvent(new Callable<FeatureObject>() {
            public FeatureObject call() throws Exception {
                ArtifactObject b = createBasicBundleObject("myBundle", "1.0", null);
                FeatureObject g = createBasicFeatureObject("myFeature");
                DistributionObject l = createBasicDistributionObject("myDistribution");
                m_artifact2featureRepository.create(b, g);
                m_feature2distributionRepository.create(g, l);
                m_distribution2targetRepository.create(l, sgo.getTargetObject());
                return g;
            }
        }, false, ArtifactObject.TOPIC_ADDED, FeatureObject.TOPIC_ADDED, DistributionObject.TOPIC_ADDED,
            Artifact2FeatureAssociation.TOPIC_ADDED, Feature2DistributionAssociation.TOPIC_ADDED,
            Distribution2TargetAssociation.TOPIC_ADDED, TOPIC_STATUS_CHANGED);

        assertTrue("We added some deployment information, so the target should need approval.", sgo.needsApprove());

        sgo.setAutoApprove(true);

        assertTrue("Turning on the autoapprove should not automatically approve whatever was waiting.", sgo.needsApprove());

        sgo.approve();

        List<Event> events = new ArrayList<Event>();
        runAndWaitForEvent(new Callable<Void>() {
            public Void call() throws Exception {
                m_repositoryAdmin.commit();
                return null;
            }
        }, false, events, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED, RepositoryAdmin.TOPIC_REFRESH);

        assertFalse("We approved the new version by hand, so we should not need approval.", sgo.needsApprove());
        assertContainsRefreshCause(events, "commit");

        runAndWaitForEvent(new Callable<Object>() {
            public Object call() throws Exception {
                ArtifactObject b = createBasicBundleObject("myBundle2", "1.0", null);
                m_artifact2featureRepository.create(b, g);
                return null;
            }
        }, false, ArtifactObject.TOPIC_ADDED, Artifact2FeatureAssociation.TOPIC_ADDED, TOPIC_STATUS_CHANGED,
            TOPIC_STATUS_CHANGED);

        runAndWaitForEvent(new Callable<Void>() {
            public Void call() throws Exception {
                m_repositoryAdmin.commit();
                return null;
            }
        }, false, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);

        assertFalse("With autoapprove on, adding new deployment information should still not need approval (at least, after the two CHANGED events).", sgo.needsApprove());

        runAndWaitForEvent(new Callable<Object>() {
            public Object call() throws Exception {
                m_statefulTargetRepository.unregister(sgo.getID());
                return null;
            }
        }, false, TOPIC_STATUS_CHANGED, TOPIC_REMOVED);
    }
View Full Code Here

            }, false, RepositoryAdmin.TOPIC_REFRESH);

            assertEquals("After refresh, we expect 1 target based on auditlogdata;", initRepoSize + 1, m_statefulTargetRepository.get().size());
           
            List<StatefulTargetObject> sgoList = m_statefulTargetRepository.get(m_bundleContext.createFilter("(id=another*)"));
            StatefulTargetObject sgo = sgoList.get(0);
            assertTrue("Expected one (anotherTarget) in the list.", sgo != null);

            // should be registered and auto approved
            assertTrue("The automation target operator should have registered anotherTarget.", sgo.isRegistered());
            assertTrue("The automation target operator should have auto-approved anotherTarget.", sgo.getAutoApprove());

            // add a target which will not be autoregistered
            events.clear();
            events.add(new Event("secondTarget", 1, 1, 1, AuditEvent.FRAMEWORK_STARTED));
            m_auditLogStore.put(events);

            // do auto target action
            processAuditlog.run();
            assertEquals("After refresh, we expect an additional target based on auditlogdata;", initRepoSize + 2, m_statefulTargetRepository.get().size());

            sgoList = m_statefulTargetRepository.get(m_bundleContext.createFilter("(id=second*)"));
            sgo = sgoList.get(0);

            // second target should not be registered
            assertFalse("The automation target operator should not have registered secondTarget.", sgo.isRegistered());
            assertFalse("The automation target operator should not have auto-approved myTarget.", sgo.getAutoApprove());
        }
        else
        {
            assertTrue("Could not get a reference to the processAuditLog task.", false);
        }
View Full Code Here

        result.setMargin(true);
        result.setSpacing(true);
        result.setSizeFull();

        final StatefulTargetObject target = getRepositoryObjectFromContext(context);

        final CheckBox registerCB = new CheckBox("Registered?");
        registerCB.setImmediate(true);
        registerCB.setEnabled(!target.isRegistered());
        registerCB.setValue(Boolean.valueOf(target.isRegistered()));

        result.addComponent(registerCB);

        final CheckBox autoApproveCB = new CheckBox("Auto approve?");
        autoApproveCB.setImmediate(true);
        autoApproveCB.setEnabled(target.isRegistered());
        autoApproveCB.setValue(Boolean.valueOf(target.getAutoApprove()));

        result.addComponent(autoApproveCB);

        final Button approveButton = new Button("Approve changes");
        approveButton.setImmediate(true);
        approveButton.setEnabled(getApproveButtonEnabledState(target));

        result.addComponent(approveButton);
       
        // Add a spacer that fill the remainder of the available space...
        result.addComponent(new Label(" "));
        result.setRowExpandRatio(3, 1.0f);
       
        // Add all listeners...
        registerCB.addListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                if (event.getButton().booleanValue()) {
                    target.register();
                    registerCB.setEnabled(!target.isRegistered());
                    autoApproveCB.setEnabled(target.isRegistered());
                }
            }
        });
        autoApproveCB.addListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                target.setAutoApprove(event.getButton().booleanValue());
                approveButton.setEnabled(getApproveButtonEnabledState(target));
            }
        });
        approveButton.addListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                target.approve();
                approveButton.setEnabled(getApproveButtonEnabledState(target));
            }
        });

        return result;
View Full Code Here

        }
        else if (Workspace.TARGET.equals(entityType) && ACTION_REGISTER.equals(action)) {
            resp.getWriter().println(m_gson.toJson(((StatefulTargetObject) repositoryObject).getRegistrationState()));
        }
        else if (Workspace.TARGET.equals(entityType) && ACTION_AUDITEVENTS.equals(action)) {
            StatefulTargetObject target = (StatefulTargetObject) repositoryObject;
            List<Event> events = target.getAuditEvents();

            String startValue = req.getParameter("start");
            String maxValue = req.getParameter("max");

            int start = (startValue == null) ? 0 : Integer.parseInt(startValue);
View Full Code Here

            resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Repository object of type " + entityType + " and identity " + entityId + " not found.");
            return;
        }

        if (Workspace.TARGET.equals(entityType) && ACTION_APPROVE.equals(action)) {
            StatefulTargetObject sto = workspace.approveTarget((StatefulTargetObject) repositoryObject);

            // Respond with the current store state...
            resp.getWriter().println(m_gson.toJson(sto.getStoreState()));
        }
        else if (Workspace.TARGET.equals(entityType) && ACTION_REGISTER.equals(action)) {
            StatefulTargetObject sto = workspace.registerTarget((StatefulTargetObject) repositoryObject);
            if (sto == null) {
                resp.sendError(HttpServletResponse.SC_CONFLICT, "Target already registered: " + entityId);
            }
            else {
                // Respond with the current registration state...
                resp.getWriter().println(m_gson.toJson(sto.getRegistrationState()));
            }
        }
        else {
            resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Unknown action for " + entityType);
        }
View Full Code Here

        DistributionObject l = createBasicDistributionObject("distribution");

        attr = new HashMap<String, String>();
        attr.put(TargetObject.KEY_ID, "myTarget");

        StatefulTargetObject sgo = m_statefulTargetRepository.preregister(attr, tags);

        m_artifact2featureRepository.create(b1, g);
        m_artifact2featureRepository.create(a1, g);
        m_artifact2featureRepository.create(a2, g);
        m_feature2distributionRepository.create(g, l);
        m_distribution2targetRepository.create(l, sgo.getTargetObject());

        sgo.approve();
       
        runAndWaitForEvent(new Callable<Void>() {
            public Void call() throws Exception {
                m_repositoryAdmin.commit();
                return null;
            }
        }, false, TOPIC_STATUS_CHANGED);
       
        assertEquals("Store state for target should still be new, because the resource processor is missing.", StoreState.New, sgo.getStoreState());
       
        // Now, add a processor for the artifact.
        attr = new HashMap<String, String>();
        attr.put(ArtifactObject.KEY_URL, "http://myprocessor");
        attr.put(BundleHelper.KEY_RESOURCE_PROCESSOR_PID, "my.processor.pid");
        attr.put(BundleHelper.KEY_SYMBOLICNAME, "my.processor.bundle");
        attr.put(BundleHelper.KEY_VERSION, "1.0.0");
        attr.put(ArtifactHelper.KEY_MIMETYPE, BundleHelper.MIMETYPE);

        ArtifactObject b2 = m_artifactRepository.create(attr, tags);

        sgo.approve();
       
        runAndWaitForEvent(new Callable<Void>() {
            public Void call() throws Exception {
                m_repositoryAdmin.commit();
                return null;
            }
        }, false, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);       

        DeploymentVersionObject dep = m_deploymentVersionRepository.getMostRecentDeploymentVersion(sgo.getID());

        DeploymentArtifact[] toDeploy = dep.getDeploymentArtifacts();

        assertEquals("We expect to find four artifacts to deploy;", 4, toDeploy.length);
        DeploymentArtifact bundle1 = toDeploy[0];
        assertEquals(b1.getURL(), bundle1.getUrl());
       
        DeploymentArtifact bundle2 = toDeploy[1];
        assertEquals(b2.getURL(), bundle2.getUrl());
        assertEquals("true", bundle2.getDirective(DeploymentArtifact.DIRECTIVE_ISCUSTOMIZER));
       
        DeploymentArtifact artifact1 = toDeploy[2];
        assertEquals(a1.getURL(), artifact1.getUrl());
        assertEquals("my.processor.pid", artifact1.getDirective(DeploymentArtifact.DIRECTIVE_KEY_PROCESSORID));
       
        DeploymentArtifact artifact2 = toDeploy[3];
        assertEquals(a2.getURL(), artifact2.getUrl());
        assertEquals("my.processor.pid", artifact2.getDirective(DeploymentArtifact.DIRECTIVE_KEY_PROCESSORID));
        assertEquals(a2.getResourceId(), artifact2.getDirective(DeploymentArtifact.DIRECTIVE_KEY_RESOURCE_ID));
       
        // Now, add a new version of the processor (ACE-373)
        assertFalse("There should be no changes.", sgo.needsApprove());

        attr = new HashMap<String, String>();
        attr.put(ArtifactObject.KEY_URL, "http://myprocessor/v2");
        attr.put(BundleHelper.KEY_RESOURCE_PROCESSOR_PID, "my.processor.pid");
        attr.put(BundleHelper.KEY_SYMBOLICNAME, "my.processor.bundle");
        attr.put(BundleHelper.KEY_VERSION, "2.0.0");
        attr.put(ArtifactHelper.KEY_MIMETYPE, BundleHelper.MIMETYPE);

        ArtifactObject b3 = m_artifactRepository.create(attr, tags);

        assertTrue("By adding a resource processor, we should have triggered a change that needs to be approved.", sgo.needsApprove());

        sgo.approve();

        runAndWaitForEvent(new Callable<Void>() {
            public Void call() throws Exception {
                m_repositoryAdmin.commit();
                return null;
            }
        }, false, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);

        dep = m_deploymentVersionRepository.getMostRecentDeploymentVersion(sgo.getID());

        toDeploy = dep.getDeploymentArtifacts();

        assertEquals("We expect to find four artifacts to deploy;", 4, toDeploy.length);
        boolean foundBundle = false;
        boolean foundProcessor = false;
        boolean foundArtifact1 = false;
        boolean foundArtifact2 = false;
        for (DeploymentArtifact a : toDeploy) {
            String url = a.getUrl();
            if (url.equals(b1.getURL())) {
                foundBundle = true;
            }
            else if (url.equals(b3.getURL())) {
                assertEquals("true", a.getDirective(DeploymentArtifact.DIRECTIVE_ISCUSTOMIZER));
                foundProcessor = true;
            }
            else if (url.equals(a1.getURL())) {
                assertEquals("my.processor.pid", a.getDirective(DeploymentArtifact.DIRECTIVE_KEY_PROCESSORID));
                foundArtifact1 = true;
            }
            else if (url.equals(a2.getURL())) {
                assertEquals("my.processor.pid", a.getDirective(DeploymentArtifact.DIRECTIVE_KEY_PROCESSORID));
                assertEquals(a2.getResourceId(), a.getDirective(DeploymentArtifact.DIRECTIVE_KEY_RESOURCE_ID));
                foundArtifact2 = true;
            }
        }
        assertTrue("Could not find bundle in deployment", foundBundle);
        assertTrue("Could not find processor in deployment", foundProcessor);
        assertTrue("Could not find artifact 1 in deployment", foundArtifact1);
        assertTrue("Could not find artifact 2 in deployment", foundArtifact2);

        // Now, let's add a new resource processor that is *older* than the one we already have.
        // Nothing should change.

        assertFalse("There should be no changes.", sgo.needsApprove());

        attr = new HashMap<String, String>();
        attr.put(ArtifactObject.KEY_URL, "http://myprocessor/v1.5");
        attr.put(BundleHelper.KEY_RESOURCE_PROCESSOR_PID, "my.processor.pid");
        attr.put(BundleHelper.KEY_SYMBOLICNAME, "my.processor.bundle");
        attr.put(BundleHelper.KEY_VERSION, "1.5.0");
        attr.put(ArtifactHelper.KEY_MIMETYPE, BundleHelper.MIMETYPE);

        m_artifactRepository.create(attr, tags);

        assertFalse("By adding an older resource processor, we should not have triggered a change.", sgo.needsApprove());

        cleanUp();

        m_dependencyManager.remove(myHelperService);
    }
View Full Code Here

        }, false, TOPIC_ADDED);

        ArtifactObject a1 = m_artifactRepository.importArtifact(noTemplateFile.toURI().toURL(), true);
        Artifact2FeatureAssociation a2g = m_artifact2featureRepository.create(a1, go);

        final StatefulTargetObject sgo = findStatefulTarget("templatetarget2");

        // create a deploymentversion
        assertTrue("With the new assignments, the SGO should need approval.", sgo.needsApprove());
       
        sgo.approve();

        runAndWaitForEvent(new Callable<Void>() {
            public Void call() throws Exception {
                m_repositoryAdmin.commit();
                return null;
            }
        }, false, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED)
       
        // find the deployment version
        DeploymentVersionObject dvo = m_deploymentVersionRepository.getMostRecentDeploymentVersion("templatetarget2");
        String inFile = tryGetStringFromURL(findXmlUrlInDeploymentObject(dvo), 10, 100);

        assertEquals(xmlHeader + noTemplateProcessed + xmlFooter, inFile);

        // try the simple template
        m_artifact2featureRepository.remove(a2g);
        a1 = m_artifactRepository.importArtifact(simpleTemplateFile.toURI().toURL(), true);
        a2g = m_artifact2featureRepository.create(a1, go);

        sgo.approve();
       
        runAndWaitForEvent(new Callable<Void>() {
            public Void call() throws Exception {
                m_repositoryAdmin.commit();
                return null;
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.