Search in sources :

Example 6 with AcsJBadParameterEx

use of alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx in project ACS by ACS-Community.

the class ManagerProxyImpl method restart_component.

/**
	 * Restarts an component.
	 * @param	id 	identification of the caller. Called has to be an owner of the component.
	 * @param	component_url	CURL of the component to be restarted.
	 * @return	CORBA reference of the restarted component, <code>null</code> if it fails.
	 */
public Object restart_component(int id, String component_url) throws NoPermissionEx {
    pendingRequests.incrementAndGet();
    try {
        // returned value
        Object retVal = null;
        // transform to CORBA specific
        URI uri = null;
        if (component_url != null)
            uri = CURLHelper.createURI(component_url);
        Component component = manager.restartComponent(id, uri);
        // extract component CORBA reference
        if (component != null)
            retVal = (Object) component.getObject();
        return retVal;
    } catch (URISyntaxException usi) {
        BadParametersException hbpe = new BadParametersException(usi.getMessage(), usi);
        reportException(hbpe);
        // rethrow CORBA specific
        throw new BAD_PARAM(usi.getMessage());
    } catch (BadParametersException bpe) {
        BadParametersException hbpe = new BadParametersException(bpe.getMessage(), bpe);
        reportException(hbpe);
        // rethrow CORBA specific
        throw new BAD_PARAM(bpe.getMessage());
    } catch (NoResourcesException nre) {
        NoResourcesException hnre = new NoResourcesException(nre.getMessage(), nre);
        reportException(hnre);
        // rethrow CORBA specific
        throw new NO_RESOURCES(nre.getMessage());
    } catch (AcsJBadParameterEx bpe) {
        reportException(bpe);
        //throw bpe.toBadParameterEx();
        throw new BAD_PARAM(bpe.getMessage());
    } catch (AcsJNoPermissionEx npe) {
        // rethrow CORBA specific
        throw npe.toNoPermissionEx();
    } catch (Throwable ex) {
        CoreException hce = new CoreException(ex.getMessage(), ex);
        reportException(hce);
        // rethrow CORBA specific
        throw new UNKNOWN(ex.getMessage());
    } finally {
        pendingRequests.decrementAndGet();
    }
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) BAD_PARAM(org.omg.CORBA.BAD_PARAM) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) BadParametersException(com.cosylab.acs.maci.BadParametersException) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) CoreException(com.cosylab.acs.maci.CoreException) Object(org.omg.CORBA.Object) UNKNOWN(org.omg.CORBA.UNKNOWN) Component(com.cosylab.acs.maci.Component) NO_RESOURCES(org.omg.CORBA.NO_RESOURCES)

Example 7 with AcsJBadParameterEx

use of alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx in project ACS by ACS-Community.

the class Helper method getNamingServiceInitial.

/**
	 * <b>This method should only be used by specialized framework code, 
	 * not by application code that uses NCs.</b>
	 * It retrieves and returns a reference to the Naming Service based on the
	 * Java property <code>ORBInitRef.NameService</code>.
	 * <p>
	 * Even specialized code that has an AcsManagerProxy instance available, 
	 * e.g. via an AdvancedComponentClient,
	 * should use the AcsManagerProxy to get the NamingContext reference:
	 * <pre>
	 * nctx = NamingContextHelper.narrow(AdvancedComponentClient.getAcsManagerProxy().get_service("NameService", false);
	 * </pre>.
	 * <p>
	 * 
	 * @return Valid reference to the Naming Service.
	 * @throws AcsJException
	 *            Thrown when there's a bad corbaloc given for the Naming Service
	 *            or the reference cannot be narrowed.
	 * @see #getNamingService()
	 * @deprecated To be removed once we have fixed the leftover usages in modules 
	 *             jcontnc, laser-core, acssamp, acssampGUI.
	 */
public static NamingContext getNamingServiceInitial(ContainerServicesBase cs) throws AcsJException {
    // acsStartJava always adds this Java property for us
    String nameCorbaloc = System.getProperty(m_nameJavaProp);
    // make sure the end-user is using acsStartJava
    if (nameCorbaloc == null || nameCorbaloc.trim().isEmpty()) {
        AcsJBadParameterEx ex = new AcsJBadParameterEx();
        ex.setReason("Missing Java property '" + m_nameJavaProp + "' for the Naming Service corbaloc!");
        throw ex;
    }
    // get the unnarrowed reference to the Naming Service
    org.omg.CORBA.Object tempCorbaObject = cs.getAdvancedContainerServices().corbaObjectFromString(nameCorbaloc);
    if (tempCorbaObject == null) {
        // very bad situation. without the naming service we cannot do anything.
        Throwable cause = new Throwable("Null reference obtained for the Naming Service, corbaloc=" + nameCorbaloc);
        // ex.setReason("Null reference obtained for the Naming Service, corbaloc=" + nameCorbaloc);
        throw new alma.ACSErrTypeCORBA.wrappers.AcsJFailedToResolveServiceEx(cause);
    }
    NamingContext ret = NamingContextHelper.narrow(tempCorbaObject);
    if (ret == null) {
        // very bad situation. without the naming service we cannot do anything.
        Throwable cause = new Throwable("Unable to narrow Naming Service reference to the correct type!");
        throw new alma.ACSErrTypeCommon.wrappers.AcsJTypeNotSupportedEx(cause);
    }
    return ret;
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) NamingContext(org.omg.CosNaming.NamingContext)

Example 8 with AcsJBadParameterEx

use of alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx in project ACS by ACS-Community.

the class ManagerImplTest method testRestartComponent.

public void testRestartComponent() {
    try {
        try {
            manager.restartComponent(0, null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: null parameter");
        }
        try {
            manager.restartComponent(Integer.MAX_VALUE, null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: null parameter");
        }
        try {
            manager.restartComponent(dummyHandle, dummyURI);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        } catch (AcsJBadParameterEx bpe) {
            fail();
        }
        TestClient client = new TestClient(clientName);
        ClientInfo info = manager.login(client);
        assertTrue(info.getHandle() != 0);
        try {
            manager.restartComponent(info.getHandle(), null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: null parameter");
        }
        URI mount = null;
        try {
            mount = new URI("MOUNT3");
            Component component = manager.restartComponent(info.getHandle(), mount);
            assertEquals(null, component);
        } catch (AcsJBadParameterEx bpe) {
            fail();
        } catch (URISyntaxException usi) {
            fail();
        }
        TestContainer container = new TestContainer("Container");
        Map supportedComponents = new HashMap();
        Component mount3COB = new TestComponent("MOUNT3");
        supportedComponents.put("MOUNT3", mount3COB);
        container.setSupportedComponents(supportedComponents);
        /*ClientInfo containerInfo = */
        manager.login(container);
        // activate
        try {
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount, true, status);
            assertEquals(mount3COB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        // restart 
        try {
            Component returnedComponent = manager.restartComponent(info.getHandle(), mount);
            assertEquals(mount3COB, returnedComponent);
        } catch (Exception ex) {
            fail();
        }
        // no owner client test
        TestClient client2 = new TestClient("thief");
        ClientInfo info2 = manager.login(client2);
        assertTrue(info2.getHandle() != 0);
        try {
            manager.restartComponent(info2.getHandle(), mount);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        } catch (AcsJBadParameterEx bpe) {
            fail();
        }
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) HashMap(java.util.HashMap) URISyntaxException(java.net.URISyntaxException) 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) Component(com.cosylab.acs.maci.Component) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with AcsJBadParameterEx

use of alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx in project ACS by ACS-Community.

the class ManagerImplTest method testReleaseComponentAsync.

public void testReleaseComponentAsync() throws Throwable {
    try {
        try {
            manager.releaseComponentAsync(0, null, null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: null parameter");
        }
        try {
            manager.releaseComponentAsync(Integer.MAX_VALUE, null, null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: null parameter");
        }
        try {
            manager.releaseComponentAsync(dummyHandle, dummyURI, null);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        } catch (AcsJBadParameterEx bpe) {
            fail();
        }
        TestClient client = new TestClient(clientName);
        ClientInfo info = manager.login(client);
        TestClient client2 = new TestClient("anotherClient");
        ClientInfo info2 = manager.login(client2);
        TestContainer container = new TestContainer("Container");
        Map supportedComponents = new HashMap();
        Component mount1COB = new TestComponent("MOUNT1");
        supportedComponents.put("MOUNT1", mount1COB);
        Component mount4COB = new TestComponent("MOUNT4", false, true);
        supportedComponents.put("MOUNT4", mount4COB);
        container.setSupportedComponents(supportedComponents);
        ClientInfo containerInfo = manager.login(container);
        // here also parallel activation will be tested (autostart and activation bellow)
        StatusHolder status = new StatusHolder();
        Component ref = manager.getComponent(info.getHandle(), new URI("MOUNT1"), true, status);
        assertEquals(mount1COB, ref);
        assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        status = new StatusHolder();
        ref = manager.getComponent(info2.getHandle(), new URI("MOUNT1"), true, status);
        assertEquals(mount1COB, ref);
        assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        ref = manager.getComponent(info.getHandle(), new URI("MOUNT4"), true, status);
        assertEquals(mount4COB, ref);
        assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        try {
            LongCompletionCallbackTestImpl lcc = new LongCompletionCallbackTestImpl();
            synchronized (lcc) {
                manager.releaseComponentAsync(info2.getHandle(), new URI("MOUNT1"), lcc);
                if (!lcc.doneFlag)
                    lcc.wait(SLEEP_TIME_MS);
                if (!lcc.doneFlag)
                    fail("callback not called");
                assertEquals(1, lcc.result);
                assertNull(lcc.exception);
                lcc.reset();
                manager.releaseComponentAsync(info.getHandle(), new URI("MOUNT1"), lcc);
                if (!lcc.doneFlag)
                    lcc.wait(SLEEP_TIME_MS);
                if (!lcc.doneFlag)
                    fail("callback not called");
                assertEquals(0, lcc.result);
                assertNull(lcc.exception);
                lcc.reset();
                manager.releaseComponentAsync(info.getHandle(), new URI("MOUNT4"), lcc);
                if (!lcc.doneFlag)
                    lcc.wait(SLEEP_TIME_MS);
                if (!lcc.doneFlag)
                    fail("callback not called");
                assertEquals(0, lcc.result);
                assertNotNull(lcc.exception);
            }
        } catch (Exception ex) {
            fail(ex.toString());
        }
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) 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) Component(com.cosylab.acs.maci.Component) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with AcsJBadParameterEx

use of alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx in project ACS by ACS-Community.

the class AlarmSystemContainerServices method checkOffShootServant.

private void checkOffShootServant(Servant servant) throws AcsJContainerServicesEx {
    if (servant == null) {
        AcsJBadParameterEx cause = new AcsJBadParameterEx();
        cause.setParameter("servant");
        cause.setParameterValue("null");
        throw new AcsJContainerServicesEx(cause);
    }
    if (!(servant instanceof OffShootOperations)) {
        String msg = "invalid offshoot servant provided. Must implement " + OffShootOperations.class.getName();
        logger.fine(msg);
        AcsJContainerServicesEx ex = new AcsJContainerServicesEx();
        ex.setContextInfo(msg);
        throw ex;
    }
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) OffShootOperations(alma.ACS.OffShootOperations) AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx)

Aggregations

AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)34 AcsJContainerServicesEx (alma.JavaContainerError.wrappers.AcsJContainerServicesEx)10 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)10 Component (com.cosylab.acs.maci.Component)10 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)10 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)10 URI (java.net.URI)9 ClientInfo (com.cosylab.acs.maci.ClientInfo)8 URISyntaxException (java.net.URISyntaxException)8 BadParametersException (com.cosylab.acs.maci.BadParametersException)7 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)6 NoDefaultComponentException (com.cosylab.acs.maci.NoDefaultComponentException)6 RemoteException (com.cosylab.acs.maci.RemoteException)6 StatusHolder (com.cosylab.acs.maci.StatusHolder)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 AcsJmaciErrTypeEx (alma.maciErrType.wrappers.AcsJmaciErrTypeEx)4 OffShootOperations (alma.ACS.OffShootOperations)3 AcsJNullPointerEx (alma.ACSErrTypeCommon.wrappers.AcsJNullPointerEx)3 ComponentDescriptor (alma.acs.component.ComponentDescriptor)3