Search in sources :

Example 11 with StatusHolder

use of com.cosylab.acs.maci.StatusHolder in project ACS by ACS-Community.

the class ManagerImpl method autoStartComponents.

/**
	 * Checks for autostart components that are to be hosed by autostart containers.
	 */
private void autoStartComponents() {
    // order is important, preserve it
    LinkedHashSet<String> activationRequestsList = new LinkedHashSet<String>();
    // get CDB access daos
    DAOProxy dao = getManagerDAOProxy();
    DAOProxy componentsDAO = getComponentsDAOProxy();
    DAOProxy containersDAO = getContainersDAOProxy();
    // no data
    if (componentsDAO == null || containersDAO == null)
        return;
    //
    if (dao != null) {
        try {
            // query startup components and add them to a list of candidates
            String[] startup = dao.get_string_seq("Startup");
            for (int i = 0; i < startup.length; i++) {
                // TODO simulator test workaround
                if (startup[i].length() == 0)
                    continue;
                activationRequestsList.add(startup[i]);
            }
        } catch (Throwable th) {
            logger.log(Level.WARNING, "Failed to retrieve list of startup components.", th);
        }
    }
    //
    // autostart components (<component>.Autostart attribute)
    //
    final String TRUE_STRING = "true";
    {
        try {
            // get names of all components
            // TODO here to check if CDB is available
            componentsDAO.get_field_data("");
            /*String[] ids =*/
            String[] ids = getComponentsList();
            // test names
            for (int i = 0; i < ids.length; i++) {
                // read name
                //readStringCharacteristics(componentsDAO, ids[i]+"/Name");
                String name = ids[i];
                if (name == null) {
                    logger.log(Level.WARNING, "Misconfigured CDB, there is no name of component '" + ids[i] + "' defined.");
                    continue;
                }
                // read autostart silently
                String autostart = readStringCharacteristics(componentsDAO, ids[i] + "/Autostart", true);
                if (autostart == null) {
                    logger.log(Level.WARNING, "Misconfigured CDB, there is no autostart attribute of component '" + ids[i] + "' defined.");
                    continue;
                } else if (autostart.equalsIgnoreCase(TRUE_STRING)) {
                    activationRequestsList.add(name);
                }
            }
        } catch (Throwable ex) {
            logger.log(Level.WARNING, "Failed to retrieve list of components.", ex);
        }
    }
    // now gather list of all containers to be started up (they will autostart components by default)
    // by filtering out all components that are not hosted by auto-start containers
    // leave only components that have "*" listed as container
    LinkedHashSet startupContainers = new LinkedHashSet();
    Iterator<String> iterator = activationRequestsList.iterator();
    while (iterator.hasNext()) {
        String name = iterator.next();
        try {
            // get container
            String containerName = readStringCharacteristics(componentsDAO, name + "/Container", true);
            if (containerName == null) {
                iterator.remove();
                continue;
            } else if (containerName.equals(ComponentSpec.COMPSPEC_ANY)) {
                // leave it in the list
                continue;
            }
            // get its deploy info
            String host = readStringCharacteristics(containersDAO, containerName + "/DeployInfo/Host", true);
            String startOnDemand = readStringCharacteristics(containersDAO, containerName + "/DeployInfo/StartOnDemand", true);
            if (host != null && startOnDemand != null && startOnDemand.equalsIgnoreCase("TRUE"))
                startupContainers.add(containerName);
            // remove (or is it auto-started by starting a container or is it not hosted by auto-start container)
            iterator.remove();
        } catch (Throwable ex) {
            logger.log(Level.WARNING, "Failed to retrieve list of components.", ex);
        }
    }
    int activated = 0;
    // autostart containers
    iterator = startupContainers.iterator();
    while (iterator.hasNext()) {
        String containerName = (String) iterator.next();
        try {
            startUpContainer(containerName);
        } catch (Throwable ex) {
            logger.log(Level.WARNING, "Failed to auto-start container to auto-start components.", ex);
        }
    }
    // activate startup components (no container specified)
    StatusHolder status = new StatusHolder();
    iterator = activationRequestsList.iterator();
    while (iterator.hasNext()) {
        String name = iterator.next();
        try {
            URI uri = CURLHelper.createURI(name);
            internalRequestComponent(this.getHandle(), uri, status);
            if (status.getStatus() != ComponentStatus.COMPONENT_ACTIVATED)
                logger.log(Level.FINE, "Failed to auto-activate requested component '" + name + "', reason: '" + status.getStatus() + "'.");
            else
                activated++;
        } catch (Throwable ex) {
            CoreException ce = new CoreException("Failed to request component '" + name + "'.", ex);
            reportException(ce);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CoreException(com.cosylab.acs.maci.CoreException) DAOProxy(com.cosylab.cdb.client.DAOProxy) URI(java.net.URI) StatusHolder(com.cosylab.acs.maci.StatusHolder)

Example 12 with StatusHolder

use of com.cosylab.acs.maci.StatusHolder in project ACS by ACS-Community.

the class ManagerImplTest method testManagerShutdownWithComponentDestruction.

public void testManagerShutdownWithComponentDestruction() {
    try {
        boolean activateOnActivation = true;
        TestContainer container = new TestContainer("Container");
        Map supportedComponents = new HashMap();
        TestContainer container2 = new TestContainer("Container2");
        Map supportedComponents2 = new HashMap();
        TestComponent mount1COB = new TestComponent("MOUNT1");
        TestHierarchicalComponent mount2HierCOB = new TestHierarchicalComponent("HierarchicalCOB2", manager, new String[] { "MOUNT3" }, true, activateOnActivation);
        TestHierarchicalComponent mount3HierCOB = new TestHierarchicalComponent("HierarchicalCOB3", manager, new String[] { "MOUNT5", "PBEND_B_01" }, true, activateOnActivation);
        TestComponent mount5COB = new TestComponent("MOUNT5");
        TestHierarchicalComponent mount4HierCOB = new TestHierarchicalComponent("HierarchicalCOB4", manager, new String[] { "MOUNT2" }, true, activateOnActivation);
        TestHierarchicalComponent psHierCOB = new TestHierarchicalComponent("HierarchicalPSCOB", manager, new String[] { "MOUNT5" }, true, activateOnActivation);
        supportedComponents.put("MOUNT1", mount1COB);
        supportedComponents.put("MOUNT2", mount2HierCOB);
        supportedComponents.put("MOUNT3", mount3HierCOB);
        supportedComponents2.put("MOUNT5", mount5COB);
        supportedComponents.put("MOUNT4", mount4HierCOB);
        supportedComponents.put("PBEND_B_01", psHierCOB);
        container.setSupportedComponents(supportedComponents);
        container2.setSupportedComponents(supportedComponents2);
        ClientInfo containerInfo = manager.login(container);
        ClientInfo containerInfo2 = manager.login(container2);
        TestAdministrator client = new TestAdministrator(administratorName);
        ClientInfo info = manager.login(client);
        try {
            Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        // activate hier. components
        URI mount2URI;
        try {
            mount2URI = new URI("MOUNT2");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount2URI, true, status);
            assertEquals(mount2HierCOB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        // activate orphan component
        URI mount1URI;
        try {
            mount1URI = new URI("MOUNT1");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount1URI, true, status);
            assertEquals(mount1COB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        // activate mount4
        URI mount4URI;
        try {
            mount4URI = new URI("MOUNT4");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount4URI, true, status);
            assertEquals(mount4HierCOB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        try {
            Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        // test activated Components
        // there should be all three Components activated
        ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(6, infos.length);
        // check container shutdown order
        int[] containerSolution = new int[] { mount4HierCOB.getHandle(), mount2HierCOB.getHandle(), mount3HierCOB.getHandle(), psHierCOB.getHandle(), mount1COB.getHandle() };
        int[] containerOrder = container.get_component_shutdown_order();
        assertNotNull(containerOrder);
        assertEquals(containerSolution.length, containerOrder.length);
        for (int i = 0; i < containerSolution.length; i++) assertEquals(containerSolution[i], containerOrder[i]);
        int[] container2Order = container2.get_component_shutdown_order();
        /*
			int[] container2Solution = new int[] {mount5COB.getHandle()}; 
			assertNotNull(container2Order);
			assertEquals(container2Solution.length, container2Order.length);
			for (int i = 0; i < container2Solution.length; i++)
				assertEquals(container2Solution[i], container2Order[i]);
			*/
        // optimization, no notification if sequence size is not less than 1
        assertNull(container2Order);
        // check shutdown
        try {
            manager.shutdown(manager.getHandle(), 1);
            try {
                Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
            } catch (InterruptedException ie) {
            }
            assertEquals(0, container.getActivatedComponents().size());
            assertEquals(0, container2.getActivatedComponents().size());
        } finally {
            // tearDown should not shutdown
            manager = null;
        }
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : HashMap(java.util.HashMap) URI(java.net.URI) RemoteException(com.cosylab.acs.maci.RemoteException) URISyntaxException(java.net.URISyntaxException) BadParametersException(com.cosylab.acs.maci.BadParametersException) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) NoDefaultComponentException(com.cosylab.acs.maci.NoDefaultComponentException) StatusHolder(com.cosylab.acs.maci.StatusHolder) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) Component(com.cosylab.acs.maci.Component) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with StatusHolder

use of com.cosylab.acs.maci.StatusHolder in project ACS by ACS-Community.

the class ManagerImplTest method testManagerToContainerStateTransferComponents.

public void testManagerToContainerStateTransferComponents() {
    TestComponent mount1COB = new TestComponent("MOUNT1");
    TestComponent mount2COB = new TestComponent("MOUNT2");
    Map supportedComponents = new HashMap();
    supportedComponents.put("MOUNT1", mount1COB);
    supportedComponents.put("MOUNT2", mount2COB);
    TestContainer container = new TestContainer("Container");
    container.setSupportedComponents(supportedComponents);
    // recovery mode
    TestContainer container2 = new TestContainer("Container", ClientType.CONTAINER, true);
    container2.setSupportedComponents(supportedComponents);
    try {
        // container login
        ClientInfo containerInfo = manager.login(container);
        TestAdministrator client = new TestAdministrator(administratorName);
        ClientInfo info = manager.login(client);
        // activate MOUNT2
        //
        URI mount1URI;
        URI mount2URI;
        try {
            mount1URI = new URI("MOUNT1");
            mount2URI = new URI("MOUNT2");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount1URI, true, status);
            assertEquals(mount1COB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
            ref = manager.getComponent(info.getHandle(), mount2URI, true, status);
            assertEquals(mount2COB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        try {
            Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        manager.logout(containerInfo.getHandle());
        // now do the trick, make container2 to login
        // this will assime container is down
        ClientInfo containerInfo2 = manager.login(container2);
        try {
            Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        // there should be 2 Components activated
        ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        Arrays.sort(infos);
        assertEquals(2, infos.length);
        assertEquals("MOUNT1", infos[0].getName());
        assertEquals("MOUNT2", infos[1].getName());
        // container2 took over
        assertEquals(containerInfo2.getHandle(), infos[0].getContainer());
        assertEquals(containerInfo2.getHandle(), infos[1].getContainer());
        // manager and client
        assertEquals(2, infos[0].getClients().size());
        assertTrue(infos[0].getClients().contains(info.getHandle()));
        assertTrue(infos[0].getClients().contains(HandleConstants.MANAGER_MASK));
        // client only
        assertEquals(1, infos[1].getClients().size());
        assertTrue(infos[1].getClients().contains(info.getHandle()));
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : HashMap(java.util.HashMap) URI(java.net.URI) RemoteException(com.cosylab.acs.maci.RemoteException) URISyntaxException(java.net.URISyntaxException) BadParametersException(com.cosylab.acs.maci.BadParametersException) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) NoDefaultComponentException(com.cosylab.acs.maci.NoDefaultComponentException) StatusHolder(com.cosylab.acs.maci.StatusHolder) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) Component(com.cosylab.acs.maci.Component) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with StatusHolder

use of com.cosylab.acs.maci.StatusHolder in project ACS by ACS-Community.

the class ManagerImplTest method testOnDemandContainer.

public void testOnDemandContainer() throws Throwable {
    TestDaemon daemon = new TestDaemon(manager, false);
    transport.registerDeamon("test", daemon);
    TestAdministrator client = new TestAdministrator(administratorName);
    ClientInfo info = manager.login(client);
    assertTrue(info.getHandle() != 0);
    URI curl = null;
    // test on-demand activation
    curl = new URI("DEMANDER");
    StatusHolder status = new StatusHolder();
    Component ref = manager.getComponent(info.getHandle(), curl, true, status);
    assertNotNull(ref);
    assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
    // check if container is logged in
    ContainerInfo[] infos = manager.getContainerInfo(info.getHandle(), new int[0], "OnDemandContainer");
    assertNotNull(infos);
    assertEquals(1, infos.length);
    // release component
    manager.releaseComponent(info.getHandle(), curl);
    Thread.sleep(SLEEP_TIME_MS);
    // there should be no container
    infos = manager.getContainerInfo(info.getHandle(), new int[0], "OnDemandContainer");
    assertNotNull(infos);
    assertEquals(0, infos.length);
    // now fail to start container
    daemon = new TestDaemon(manager, true);
    transport.registerDeamon("test", daemon);
    try {
        status = new StatusHolder();
        ref = manager.getComponent(info.getHandle(), curl, true, status);
        fail();
    } catch (AcsJCannotGetComponentEx e) {
        System.out.println("This is OK: " + e.toString());
    }
    // no daemon case
    transport.registerDeamon("test", null);
    try {
        status = new StatusHolder();
        ref = manager.getComponent(info.getHandle(), curl, true, status);
        fail("Expected AcsJCannotGetComponentEx");
    } catch (AcsJCannotGetComponentEx e) {
        System.out.println("This is OK: " + e.toString());
    } catch (AcsJNoPermissionEx e) {
        fail();
    }
}
Also used : AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ContainerInfo(com.cosylab.acs.maci.ContainerInfo) ClientInfo(com.cosylab.acs.maci.ClientInfo) Component(com.cosylab.acs.maci.Component) URI(java.net.URI) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx) StatusHolder(com.cosylab.acs.maci.StatusHolder)

Example 15 with StatusHolder

use of com.cosylab.acs.maci.StatusHolder in project ACS by ACS-Community.

the class ManagerImplTest method testGetCyclicHierachicalComponent.

/*
	This test was disabled, since construct() is not yet implemented as it should be,
	now it activation (named) lock is aquired also when construct() method is called!
	 
	public void testGetCyclicHierachicalComponentConstructCase()
	{
		// activation of subcomponents is requested in construct() method 
		testGetCyclicHierachicalComponent(false);
	}

	*/
private void testGetCyclicHierachicalComponent(boolean constructCase) {
    try {
        TestContainer container = new TestContainer("Container");
        Map supportedComponents = new HashMap();
        // MOUNT2 -> MOUNT2 cycle
        TestHierarchicalComponent mount2HierCOB = new TestHierarchicalComponent("CyclicHierarchical", manager, new String[] { "MOUNT2" }, true, constructCase);
        supportedComponents.put("MOUNT2", mount2HierCOB);
        // MOUNT3 -> MOUNT5 -> PBEND_B_01 -> MOUNT3 cycle
        TestHierarchicalComponent mount3HierCOB = new TestHierarchicalComponent("MOUNT3", manager, new String[] { "MOUNT4" }, true, constructCase);
        supportedComponents.put("MOUNT3", mount3HierCOB);
        TestHierarchicalComponent mount4HierCOB = new TestHierarchicalComponent("MOUNT4", manager, new String[] { "PBEND_B_01" }, true, constructCase);
        supportedComponents.put("MOUNT4", mount4HierCOB);
        TestHierarchicalComponent pbendHierCOB = new TestHierarchicalComponent("PBEND_B_01", manager, new String[] { "MOUNT3" }, true, constructCase);
        supportedComponents.put("PBEND_B_01", pbendHierCOB);
        container.setSupportedComponents(supportedComponents);
        TestAdministrator client = new TestAdministrator(administratorName);
        ClientInfo info = manager.login(client);
        // test case when container is unable to activate startup Component - MOUNT1
        ClientInfo containerInfo = manager.login(container);
        long startTime = System.currentTimeMillis();
        // this will cause cyclic depedency...
        try {
            StatusHolder status;
            Component ref;
            URI mount2URI = new URI("MOUNT2");
            status = new StatusHolder();
            ref = manager.getComponent(info.getHandle(), mount2URI, true, status);
            fail();
        } catch (AcsJCannotGetComponentEx e) {
            System.out.println("This is OK: cyclic dependency " + e.toString());
        } catch (Exception ex) {
            fail();
        }
        long stopTime = System.currentTimeMillis();
        // cyclic dependency should be detected, not deadlock detected
        if (stopTime - startTime > 30000)
            fail("Cyclic dependency detection is too slow.");
        startTime = System.currentTimeMillis();
        // this will cause cyclic depedency...
        try {
            URI mount3URI = new URI("MOUNT3");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount3URI, true, status);
            fail();
        } catch (AcsJCannotGetComponentEx e) {
            System.out.println("This is OK: cyclic dependency " + e.toString());
        } catch (Exception ex) {
            fail();
        }
        stopTime = System.currentTimeMillis();
        // cyclic dependency should be detected, not deadlock detected
        if (stopTime - startTime > 30000)
            fail("Cyclic dependency detection is too slow.");
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : HashMap(java.util.HashMap) URI(java.net.URI) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx) RemoteException(com.cosylab.acs.maci.RemoteException) URISyntaxException(java.net.URISyntaxException) BadParametersException(com.cosylab.acs.maci.BadParametersException) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) NoDefaultComponentException(com.cosylab.acs.maci.NoDefaultComponentException) StatusHolder(com.cosylab.acs.maci.StatusHolder) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo) Component(com.cosylab.acs.maci.Component) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

StatusHolder (com.cosylab.acs.maci.StatusHolder)24 URI (java.net.URI)23 Component (com.cosylab.acs.maci.Component)19 URISyntaxException (java.net.URISyntaxException)19 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)18 BadParametersException (com.cosylab.acs.maci.BadParametersException)17 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)17 ClientInfo (com.cosylab.acs.maci.ClientInfo)16 NoDefaultComponentException (com.cosylab.acs.maci.NoDefaultComponentException)16 RemoteException (com.cosylab.acs.maci.RemoteException)16 HashMap (java.util.HashMap)16 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)15 Map (java.util.Map)15 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)8 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)6 CoreException (com.cosylab.acs.maci.CoreException)5 DAOProxy (com.cosylab.cdb.client.DAOProxy)4 AcsJComponentSpecIncompatibleWithActiveComponentEx (alma.maciErrType.wrappers.AcsJComponentSpecIncompatibleWithActiveComponentEx)3 AcsJIncompleteComponentSpecEx (alma.maciErrType.wrappers.AcsJIncompleteComponentSpecEx)3 AcsJInvalidComponentSpecEx (alma.maciErrType.wrappers.AcsJInvalidComponentSpecEx)3