Search in sources :

Example 16 with ServiceName

use of org.jboss.msc.service.ServiceName in project wildfly by wildfly.

the class JMSQueueRemove method performRuntime.

protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    final String name = address.getLastElement().getValue();
    ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
    ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
    JMSServerControl control = JMSServerControl.class.cast(server.getManagementService().getResource(ResourceNames.JMS_SERVER));
    if (control != null) {
        try {
            control.destroyQueue(name, true);
        } catch (Exception e) {
            throw new OperationFailedException(e);
        }
    }
    context.removeService(JMSServices.getJmsQueueBaseServiceName(serviceName).append(name));
    for (String entry : CommonAttributes.DESTINATION_ENTRIES.unwrap(context, model)) {
        final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(entry);
        ServiceName binderServiceName = bindInfo.getBinderServiceName();
        context.removeService(binderServiceName);
    }
    for (String legacyEntry : CommonAttributes.LEGACY_ENTRIES.unwrap(context, model)) {
        final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(legacyEntry);
        ServiceName binderServiceName = bindInfo.getBinderServiceName();
        context.removeService(binderServiceName);
    }
}
Also used : JMSServerControl(org.apache.activemq.artemis.api.jms.management.JMSServerControl) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 17 with ServiceName

use of org.jboss.msc.service.ServiceName in project wildfly by wildfly.

the class SecurityRoleReadAttributeHandler method executeRuntimeStep.

@Override
public void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString();
    PathAddress pathAddress = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
    String addressName = pathAddress.getElement(pathAddress.size() - 2).getValue();
    String roleName = pathAddress.getLastElement().getValue();
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
    ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
    AddressControl control = AddressControl.class.cast(server.getManagementService().getResource(ResourceNames.CORE_ADDRESS + addressName));
    if (control == null) {
        PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
        throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
    }
    try {
        String rolesAsJSON = control.getRolesAsJSON();
        ModelNode res = ModelNode.fromJSONString(rolesAsJSON);
        ModelNode roles = ManagementUtil.convertSecurityRole(res);
        ModelNode matchedRole = findRole(roleName, roles);
        if (matchedRole == null || !matchedRole.hasDefined(attributeName)) {
            throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(attributeName);
        }
        boolean value = matchedRole.get(attributeName).asBoolean();
        context.getResult().set(value);
    } catch (Exception e) {
        context.getFailureDescription().set(e.getLocalizedMessage());
    }
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 18 with ServiceName

use of org.jboss.msc.service.ServiceName in project wildfly by wildfly.

the class SecuritySettingAdd method getServer.

static ActiveMQServer getServer(final OperationContext context, ModelNode operation) {
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    final ServiceController<?> controller = context.getServiceRegistry(true).getService(serviceName);
    if (controller != null) {
        return ActiveMQServer.class.cast(controller.getValue());
    }
    return null;
}
Also used : ServiceName(org.jboss.msc.service.ServiceName)

Example 19 with ServiceName

use of org.jboss.msc.service.ServiceName in project wildfly by wildfly.

the class WritableServiceBasedNamingStoreTestCase method testMultipleOwnersBindingReferences.

@Test
public void testMultipleOwnersBindingReferences() throws Exception {
    final Name name = new CompositeName("test");
    final ServiceName serviceName = store.buildServiceName(name);
    final Object value = new Object();
    // ensure bind does not exists
    try {
        store.lookup(name);
        fail("Should have thrown name not found");
    } catch (NameNotFoundException expect) {
    }
    // ensure the owners RuntimeBindReleaseService have no reference to the future bind
    final RuntimeBindReleaseService.References fooDuBindingReferences = (RuntimeBindReleaseService.References) container.getService(JndiNamingDependencyProcessor.serviceName(OWNER_FOO)).getValue();
    assertFalse(fooDuBindingReferences.contains(serviceName));
    final RuntimeBindReleaseService.References barDuBindingReferences = (RuntimeBindReleaseService.References) container.getService(JndiNamingDependencyProcessor.serviceName(OWNER_BAR)).getValue();
    assertFalse(barDuBindingReferences.contains(serviceName));
    WritableServiceBasedNamingStore.pushOwner(OWNER_FOO);
    try {
        store.bind(name, value);
        // Foo's RuntimeBindReleaseService should now have a reference to the new bind
        assertTrue(fooDuBindingReferences.contains(serviceName));
        // Bar's RuntimeBindReleaseService reference to the bind should not exist
        assertFalse(barDuBindingReferences.contains(serviceName));
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
    WritableServiceBasedNamingStore.pushOwner(OWNER_BAR);
    try {
        store.rebind(name, value);
        // after rebind, Foo's RuntimeBindReleaseService reference to the bind should still exist
        assertTrue(fooDuBindingReferences.contains(serviceName));
        // after rebind, Bar's RuntimeBindReleaseService reference to the bind should now exist
        assertTrue(barDuBindingReferences.contains(serviceName));
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
    WritableServiceBasedNamingStore.pushOwner(OWNER_FOO);
    try {
        store.unbind(name);
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) NameNotFoundException(javax.naming.NameNotFoundException) CompositeName(javax.naming.CompositeName) RuntimeBindReleaseService(org.jboss.as.naming.deployment.RuntimeBindReleaseService) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) ServiceName(org.jboss.msc.service.ServiceName) Test(org.junit.Test)

Example 20 with ServiceName

use of org.jboss.msc.service.ServiceName in project wildfly by wildfly.

the class ServiceBasedNamingStoreTestCase method testStoredContext.

@Test
public void testStoredContext() throws Exception {
    final ServiceName bindingName = ServiceName.JBOSS.append("foo-stored").append("again");
    bindObject(bindingName, new Context() {

        @Override
        public Object lookup(Name name) throws NamingException {
            if ("blah/blah2".equals(name.toString())) {
                return new Integer(5);
            }
            return null;
        }

        @Override
        public Object lookup(String name) throws NamingException {
            return lookup(new CompositeName(name));
        }

        @Override
        public void bind(Name name, Object obj) throws NamingException {
        }

        @Override
        public void bind(String name, Object obj) throws NamingException {
        }

        @Override
        public void rebind(Name name, Object obj) throws NamingException {
        }

        @Override
        public void rebind(String name, Object obj) throws NamingException {
        }

        @Override
        public void unbind(Name name) throws NamingException {
        }

        @Override
        public void unbind(String name) throws NamingException {
        }

        @Override
        public void rename(Name oldName, Name newName) throws NamingException {
        }

        @Override
        public void rename(String oldName, String newName) throws NamingException {
        }

        @Override
        public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
            return null;
        }

        @Override
        public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
            return null;
        }

        @Override
        public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
            if (!"hi/there".equals(name.toString()))
                throw new IllegalArgumentException("Expected hi/there");
            return null;
        }

        @Override
        public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
            return null;
        }

        @Override
        public void destroySubcontext(Name name) throws NamingException {
        }

        @Override
        public void destroySubcontext(String name) throws NamingException {
        }

        @Override
        public Context createSubcontext(Name name) throws NamingException {
            return null;
        }

        @Override
        public Context createSubcontext(String name) throws NamingException {
            return null;
        }

        @Override
        public Object lookupLink(Name name) throws NamingException {
            return null;
        }

        @Override
        public Object lookupLink(String name) throws NamingException {
            return null;
        }

        @Override
        public NameParser getNameParser(Name name) throws NamingException {
            return null;
        }

        @Override
        public NameParser getNameParser(String name) throws NamingException {
            return null;
        }

        @Override
        public Name composeName(Name name, Name prefix) throws NamingException {
            return null;
        }

        @Override
        public String composeName(String name, String prefix) throws NamingException {
            return null;
        }

        @Override
        public Object addToEnvironment(String propName, Object propVal) throws NamingException {
            return null;
        }

        @Override
        public Object removeFromEnvironment(String propName) throws NamingException {
            return null;
        }

        @Override
        public Hashtable<?, ?> getEnvironment() throws NamingException {
            return null;
        }

        @Override
        public void close() throws NamingException {
        }

        @Override
        public String getNameInNamespace() throws NamingException {
            return null;
        }
    });
    final NamingContext ctx = new NamingContext(new CompositeName(), store, null);
    final Object obj = ctx.lookup(new CompositeName("foo-stored/again/blah/blah2"));
    ctx.listBindings("foo-stored/again/hi/there");
    assertNotNull(obj);
    assertEquals(new Integer(5), obj);
}
Also used : StopContext(org.jboss.msc.service.StopContext) Context(javax.naming.Context) StartContext(org.jboss.msc.service.StartContext) Hashtable(java.util.Hashtable) CompositeName(javax.naming.CompositeName) NamingEnumeration(javax.naming.NamingEnumeration) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) ServiceName(org.jboss.msc.service.ServiceName) ServiceName(org.jboss.msc.service.ServiceName) NamingException(javax.naming.NamingException) NameParser(javax.naming.NameParser) Test(org.junit.Test)

Aggregations

ServiceName (org.jboss.msc.service.ServiceName)289 ServiceTarget (org.jboss.msc.service.ServiceTarget)56 PathAddress (org.jboss.as.controller.PathAddress)54 ModelNode (org.jboss.dmr.ModelNode)48 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)44 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)40 OperationFailedException (org.jboss.as.controller.OperationFailedException)33 Module (org.jboss.modules.Module)23 ServiceController (org.jboss.msc.service.ServiceController)23 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)22 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)22 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)19 BinderService (org.jboss.as.naming.service.BinderService)18 HashSet (java.util.HashSet)17 ContextNames (org.jboss.as.naming.deployment.ContextNames)17 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)15 HashMap (java.util.HashMap)14 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)14 ArrayList (java.util.ArrayList)13 OperationContext (org.jboss.as.controller.OperationContext)12