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);
}
}
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());
}
}
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;
}
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();
}
}
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);
}
Aggregations