void execute(OperationContext context, ModelNode operation) throws OperationFailedException { operation.get(OPERATION_HEADERS).remove(PrepareStepHandler.EXECUTE_FOR_COORDINATOR); addSteps(context, operation, null, true); context.completeStep(); }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { validator.validate(operation); ThreadMXBean mbean = ManagementFactory.getThreadMXBean(); try { long id = operation.require(PlatformMBeanConstants.ID).asLong(); ThreadInfo info = null; if (operation.hasDefined(PlatformMBeanConstants.MAX_DEPTH)) { info = mbean.getThreadInfo(id, operation.require(PlatformMBeanConstants.MAX_DEPTH).asInt()); } else { info = mbean.getThreadInfo(id); } final ModelNode result = context.getResult(); if (info != null) { result.set(PlatformMBeanUtil.getDetypedThreadInfo(info, mbean.isThreadCpuTimeSupported())); } } catch (SecurityException e) { throw new OperationFailedException(new ModelNode().set(e.toString())); } context.completeStep(); }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR)); final PathElement element = address.getLastElement(); final String serverName = element.getValue(); final ModelNode subModel = context.readModel(PathAddress.EMPTY_ADDRESS); final boolean isStart; if (subModel.hasDefined(AUTO_START)) { isStart = subModel.get(AUTO_START).asBoolean(); } else { isStart = true; } ServerStatus status = serverInventory.determineServerStatus(serverName); if (status == ServerStatus.STOPPED) { status = isStart ? status : ServerStatus.DISABLED; } if (status != null) { context.getResult().set(status.toString()); context.completeStep(); } else { throw new OperationFailedException(new ModelNode().set("Failed to get server status")); } }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { ModelNode model = context.createResource(PathAddress.EMPTY_ADDRESS).getModel(); SecurityRealmResourceDefinition.MAP_GROUPS_TO_ROLES.validateAndSet(operation, model); // Add a step validating that we have the correct authentication and authorization child // resources ModelNode validationOp = AuthenticationValidatingHandler.createOperation(operation); context.addStep( validationOp, AuthenticationValidatingHandler.INSTANCE, OperationContext.Stage.MODEL); validationOp = AuthorizationValidatingHandler.createOperation(operation); context.addStep( validationOp, AuthorizationValidatingHandler.INSTANCE, OperationContext.Stage.MODEL); context.addStep( new OperationStepHandler() { @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { // Install another RUNTIME handler to actually install the services. This will run after // the // RUNTIME handler for any child resources. Doing this will ensure that child resource // handlers don't // see the installed services and can just ignore doing any RUNTIME stage work context.addStep(ServiceInstallStepHandler.INSTANCE, OperationContext.Stage.RUNTIME); context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); } }, OperationContext.Stage.RUNTIME); context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); }
@Override public void execute(final OperationContext context, final ModelNode ignored) throws OperationFailedException { final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); final ModelNode model = resource.getModel(); for (final AttributeDefinition definition : InterfaceDescription.ROOT_ATTRIBUTES) { final String attributeName = definition.getName(); final boolean has = model.hasDefined(attributeName); if (!has && isRequired(definition, model)) { throw new OperationFailedException(new ModelNode().set(MESSAGES.required(attributeName))); } if (has) { if (!isAllowed(definition, model)) { // TODO probably move this into AttributeDefinition String[] alts = definition.getAlternatives(); StringBuilder sb = null; if (alts != null) { for (String alt : alts) { if (model.hasDefined(alt)) { if (sb == null) { sb = new StringBuilder(); } else { sb.append(", "); } sb.append(alt); } } } throw new OperationFailedException( new ModelNode().set(MESSAGES.invalidAttributeCombo(attributeName, sb))); } } } context.completeStep(); }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (context.getType() == OperationContext.Type.SERVER) { context.addStep( new OperationStepHandler() { @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { ServiceController<?> controller = context.getServiceRegistry(false).getService(ModClusterService.NAME); ModCluster modcluster = (ModCluster) controller.getValue(); ROOT_LOGGER.debugf("add-proxy: %s", operation); Proxy proxy = new Proxy(operation); modcluster.addProxy(proxy.host, proxy.port); context.completeStep(); } }, OperationContext.Stage.RUNTIME); } context.completeStep(); }
@Override protected boolean applyUpdateToRuntime( OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, org.jboss.as.controller.AbstractWriteAttributeHandler.HandbackHolder<Void> handbackHolder) throws OperationFailedException { if (attributeName.equals(TrackerExtension.TICK)) { final String suffix = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)) .getLastElement() .getValue(); TrackerService service = (TrackerService) context .getServiceRegistry(true) .getRequiredService(TrackerService.createServiceName(suffix)) .getValue(); service.setTick(resolvedValue.asLong()); context.completeStep(); } return false; }
@Override protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException { // Address is of the form: // /subsystem=infinispan/cache-container=*/*-cache=*/transaction=TRANSACTION PathAddress address = context.getCurrentAddress(); String containerName = address.getElement(address.size() - 3).getValue(); String cacheName = address.getElement(address.size() - 2).getValue(); String name = operation.require(ModelDescriptionConstants.NAME).asString(); TransactionMetric metric = TransactionMetric.forName(name); if (metric == null) { context.getFailureDescription().set(InfinispanLogger.ROOT_LOGGER.unknownMetric(name)); } else { Cache<?, ?> cache = ServiceContainerHelper.findValue( context.getServiceRegistry(false), CacheServiceName.CACHE.getServiceName(containerName, cacheName)); if (cache != null) { TxInterceptor interceptor = CacheMetric.findInterceptor(cache, TxInterceptor.class); context .getResult() .set((interceptor != null) ? metric.getValue(interceptor) : new ModelNode(0)); } } context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER); }
/* * (non-Javadoc) * * @see * org.jboss.as.controller.OperationStepHandler#execute(org.jboss.as.controller * .OperationContext, org.jboss.dmr.ModelNode) */ @Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { context.addStep( new OperationStepHandler() { @Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { final ModelNode components = context.getResult(); final ServiceController<?> controller = context .getServiceRegistry(false) .getRequiredService(SwitchYardAdminService.SERVICE_NAME); SwitchYard switchYard = SwitchYard.class.cast(controller.getService().getValue()); for (Component component : switchYard.getComponents()) { components.add(component.getName()); } context.completeStep(); } }, OperationContext.Stage.RUNTIME); context.completeStep(); }
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { ModelNode model = context.readModel(PathAddress.EMPTY_ADDRESS); context .getResult() .add(createAddOperation(model.require(CommonAttributes.DEFAULT_DATASOURCE).asString())); context.completeStep(); }
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); final List<byte[]> removedHashes = DeploymentUtils.getDeploymentHash(resource); final ModelNode model = context.readModel(PathAddress.EMPTY_ADDRESS); context.removeResource(PathAddress.EMPTY_ADDRESS); if (context.getType() == OperationContext.Type.SERVER) { context.addStep( new OperationStepHandler() { public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { String deploymentUnitName = null; boolean enabled = model.hasDefined(ENABLED) ? model.get(ENABLED).asBoolean() : true; if (enabled) { final ModelNode opAddr = operation.get(OP_ADDR); final PathAddress address = PathAddress.pathAddress(opAddr); final String name = address.getLastElement().getValue(); deploymentUnitName = model.hasDefined(RUNTIME_NAME) ? model.get(RUNTIME_NAME).asString() : name; final ServiceName deploymentUnitServiceName = Services.deploymentUnitName(deploymentUnitName); context.removeService(deploymentUnitServiceName); context.removeService(deploymentUnitServiceName.append("contents")); } if (context.completeStep() == OperationContext.ResultAction.ROLLBACK) { recoverServices(context, operation, model); if (enabled && context.hasFailureDescription()) { ServerLogger.ROOT_LOGGER.undeploymentRolledBack( deploymentUnitName, context.getFailureDescription().asString()); } else if (enabled) { ServerLogger.ROOT_LOGGER.undeploymentRolledBackWithNoMessage(deploymentUnitName); } } else { if (enabled) { ServerLogger.ROOT_LOGGER.deploymentUndeployed(deploymentUnitName); } if (standalone) { for (byte[] hash : removedHashes) { try { contentRepository.removeContent(hash); } catch (Exception e) { // TODO log.infof(e, "Exception occurred removing %s", hash); } } } } } }, OperationContext.Stage.RUNTIME); } context.completeStep(); }
private void executeQueue(OperationContext context) { DmrActions dmr = new DmrActions(context); for (ModelNode job : queue) { dmr.addStepToContext(job); log.tracef("Job %s added to context.", job.toString()); } context.completeStep(); log.debug("context.completeStep"); }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { try { getMemoryPoolMXBean(operation).resetPeakUsage(); } catch (SecurityException e) { throw new OperationFailedException(new ModelNode().set(e.toString())); } context.completeStep(); }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final ModelNode subModel = context.readModel(PathAddress.EMPTY_ADDRESS); boolean master = subModel .get(ModelDescriptionConstants.DOMAIN_CONTROLLER) .hasDefined(ModelDescriptionConstants.LOCAL); context.getResult().set(master); context.completeStep(); }
@Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { final ModelNode address = PathAddress.pathAddress( PathAddress.pathAddress(operation.require(OP_ADDR)).getLastElement()) .toModelNode(); final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); final ModelNode result = context.getResult(); describe(resource, address, result, context.getResourceRegistration()); context.completeStep(); }
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { ModelNode result = context.getResult(); result.add( Util.getEmptyOperation( ADD, pathAddress(PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME)))); // TODO if child resources are developed, add operations to create those context.completeStep(); }
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final ModelNode add = createEmptyAddOperation(); final ModelNode model = context.readModel(PathAddress.EMPTY_ADDRESS); if (model.hasDefined(BEAN_VALIDATION_ENABLED)) { add.get(BEAN_VALIDATION_ENABLED).set(model.get(BEAN_VALIDATION_ENABLED)); } if (model.hasDefined(ARCHIVE_VALIDATION_ENABLED)) { add.get(ARCHIVE_VALIDATION_ENABLED).set(model.get(ARCHIVE_VALIDATION_ENABLED)); } if (model.hasDefined(ARCHIVE_VALIDATION_FAIL_ON_ERROR)) { add.get(ARCHIVE_VALIDATION_FAIL_ON_ERROR).set(model.get(ARCHIVE_VALIDATION_FAIL_ON_ERROR)); } if (model.hasDefined(ARCHIVE_VALIDATION_FAIL_ON_WARN)) { add.get(ARCHIVE_VALIDATION_FAIL_ON_WARN).set(model.get(ARCHIVE_VALIDATION_FAIL_ON_WARN)); } if (model.hasDefined(CACHED_CONNECTION_MANAGER_DEBUG)) { add.get(CACHED_CONNECTION_MANAGER_DEBUG).set(model.get(CACHED_CONNECTION_MANAGER_DEBUG)); } if (model.hasDefined(CACHED_CONNECTION_MANAGER_ERROR)) { add.get(CACHED_CONNECTION_MANAGER_ERROR).set(model.get(CACHED_CONNECTION_MANAGER_ERROR)); } final ModelNode result = context.getResult(); result.add(add); if (model.hasDefined(THREAD_POOL)) { ModelNode pools = model.get(THREAD_POOL); for (Property poolProp : pools.asPropertyList()) { if (poolProp.getName().equals(LONG_RUNNING_THREADS)) { addBoundedQueueThreadPool( result, poolProp.getValue(), PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, SUBSYSTEM_NAME), PathElement.pathElement(THREAD_POOL, LONG_RUNNING_THREADS)); } else if (poolProp.getName().equals(SHORT_RUNNING_THREADS)) { addBoundedQueueThreadPool( result, poolProp.getValue(), PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, SUBSYSTEM_NAME), PathElement.pathElement(THREAD_POOL, SHORT_RUNNING_THREADS)); } } } context.completeStep(); }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final List<ServiceController<?>> newControllers = new ArrayList<ServiceController<?>>(); final String realmName = ManagementUtil.getSecurityRealmName(operation); final ModelNode model = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS)); SecurityRealmAddHandler.INSTANCE.installServices( context, realmName, model, new ServiceVerificationHandler(), newControllers); context.completeStep( new OperationContext.RollbackHandler() { @Override public void handleRollback(OperationContext context, ModelNode operation) { for (ServiceController<?> sc : newControllers) { context.removeService(sc); } } }); }
void execute(OperationContext context, ModelNode operation) throws OperationFailedException { ModelNode headers = operation.get(OPERATION_HEADERS); headers.remove(EXECUTE_FOR_COORDINATOR); final ModelNode missingResources = operation .get(OPERATION_HEADERS) .remove(DomainControllerRuntimeIgnoreTransformationRegistry.MISSING_DOMAIN_RESOURCES); if (headers.hasDefined(DomainControllerLockIdUtils.DOMAIN_CONTROLLER_LOCK_ID)) { int id = headers.remove(DomainControllerLockIdUtils.DOMAIN_CONTROLLER_LOCK_ID).asInt(); context.attach(DomainControllerLockIdUtils.DOMAIN_CONTROLLER_LOCK_ID_ATTACHMENT, id); } final HostControllerExecutionSupport hostControllerExecutionSupport = addSteps(context, operation, null, true); // Add the missing resources step first if (missingResources != null) { ModelNode applyMissingResourcesOp = ApplyMissingDomainModelResourcesHandler.createPiggyBackedMissingDataOperation( missingResources); context.addStep( applyMissingResourcesOp, applyMissingDomainModelResourcesHandler, OperationContext.Stage.MODEL, true); } // In case the actual operation fails make sure the result still gets formatted context.completeStep( new OperationContext.RollbackHandler() { @Override public void handleRollback(OperationContext context, ModelNode operation) { if (hostControllerExecutionSupport.getDomainOperation() != null) { final ModelNode domainResult = hostControllerExecutionSupport.getFormattedDomainResult(context.getResult()); context.getResult().set(domainResult); } } }); }
@Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); final ModelNode model = resource.getModel(); final String name = operation.require(ModelDescriptionConstants.NAME).asString(); final AttributeDefinition def = ATTRIBUTES.get(name); if (def == null) { throw new OperationFailedException(new ModelNode().set(MESSAGES.unknownAttribute(name))); } final ModelNode value = operation.get(ModelDescriptionConstants.VALUE); def.getValidator().validateParameter(name, value); model.get(name).set(value); context.reloadRequired(); // Verify the model in a later step context.addStep(VERIFY_HANDLER, OperationContext.Stage.VERIFY); if (context.completeStep() != OperationContext.ResultAction.KEEP) { context.revertReloadRequired(); } }
/** {@inheritDoc} */ @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (contentRepository != null) { try { InputStream is = getContentInputStream(context, operation); try { byte[] hash = contentRepository.addContent(is); context.getResult().set(hash); } finally { safeClose(is); } } catch (IOException e) { throw new OperationFailedException(new ModelNode().set(e.toString())); } } // else this is a slave domain controller and we should ignore this operation context.completeStep(); }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (context.isNormalServer() && context.getServiceRegistry(false).getService(ModClusterService.NAME) != null) { context.addStep( new OperationStepHandler() { @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { ServiceController<?> controller = context.getServiceRegistry(false).getService(ModClusterService.NAME); ModCluster modcluster = (ModCluster) controller.getValue(); modcluster.disable(); context.completeStep(); } }, OperationContext.Stage.RUNTIME); } context.completeStep(); }
@Override protected void executeRuntimeStep(OperationContext context, ModelNode operation) { // Address is of the form: /subsystem=infinispan/cache-container=*/*-cache=* PathAddress address = context.getCurrentAddress(); String containerName = address.getElement(address.size() - 2).getValue(); String cacheName = address.getElement(address.size() - 1).getValue(); String name = Operations.getAttributeName(operation); CacheMetric metric = CacheMetric.forName(name); if (metric == null) { context.getFailureDescription().set(InfinispanLogger.ROOT_LOGGER.unknownMetric(name)); } else { Cache<?, ?> cache = ServiceContainerHelper.findValue( context.getServiceRegistry(false), CacheServiceName.CACHE.getServiceName(containerName, cacheName)); if (cache != null) { context.getResult().set(metric.getValue(cache)); } } context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER); }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { AuthorizationResult authorizationResult = context.authorize(operation); if (authorizationResult.getDecision() == AuthorizationResult.Decision.DENY) { throw ControllerLogger.ROOT_LOGGER.unauthorized( operation.get(OP).asString(), context.getCurrentAddress(), authorizationResult.getExplanation()); } try { SnapshotInfo info = persister.listSnapshots(); ModelNode result = context.getResult(); result.get(ModelDescriptionConstants.DIRECTORY).set(info.getSnapshotDirectory()); result.get(ModelDescriptionConstants.NAMES).setEmptyList(); for (String name : info.names()) { result.get(ModelDescriptionConstants.NAMES).add(name); } } catch (Exception e) { throw new OperationFailedException(e); } context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); }
public void execute(OperationContext context, ModelNode operation) { final ModelNode model = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel(); // On boot we invoke this op but we may not want to store a default value the model boolean persist = operation.get(PERSISTENT).asBoolean(true); if (persist) { model.get(ENABLED).set(true); } else if (model.hasDefined(ENABLED) && !model.get(ENABLED).asBoolean()) { // Just clear the "false" value that gets stored by default model.get(ENABLED).set(new ModelNode()); } if (context.getType() == OperationContext.Type.SERVER) { context.addStep( new OperationStepHandler() { public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final ServiceTarget serviceTarget = context.getServiceTarget(); final ServiceVerificationHandler verificationHandler = new ServiceVerificationHandler(); final ModelNode address = operation.require(OP_ADDR); final String dsName = PathAddress.pathAddress(address).getLastElement().getValue(); final String jndiName = model.get(JNDINAME.getName()).asString(); final ServiceRegistry registry = context.getServiceRegistry(true); final List<ServiceName> serviceNames = registry.getServiceNames(); if (isXa()) { final ModifiableXaDataSource dataSourceConfig; try { dataSourceConfig = xaFrom(context, model); } catch (ValidateException e) { throw new OperationFailedException( e, new ModelNode() .set( MESSAGES.failedToCreate( "XaDataSource", operation, e.getLocalizedMessage()))); } final ServiceName xaDataSourceConfigServiceName = XADataSourceConfigService.SERVICE_NAME_BASE.append(dsName); final XADataSourceConfigService xaDataSourceConfigService = new XADataSourceConfigService(dataSourceConfig); final ServiceBuilder<?> builder = serviceTarget.addService( xaDataSourceConfigServiceName, xaDataSourceConfigService); builder.addListener(verificationHandler); for (ServiceName name : serviceNames) { if (xaDataSourceConfigServiceName .append("xa-datasource-properties") .isParentOf(name)) { final ServiceController<?> xaConfigProperyController = registry.getService(name); XaDataSourcePropertiesService xaPropService = (XaDataSourcePropertiesService) xaConfigProperyController.getService(); if (xaConfigProperyController != null) { if (!ServiceController.State.UP.equals( xaConfigProperyController.getState())) { xaConfigProperyController.setMode(ServiceController.Mode.ACTIVE); builder.addDependency( name, String.class, xaDataSourceConfigService.getXaDataSourcePropertyInjector( xaPropService.getName())); } else { throw new OperationFailedException( new ModelNode() .set( MESSAGES.serviceAlreadyStarted( "Data-source.xa-config-property", name))); } } else { throw new OperationFailedException( new ModelNode() .set( MESSAGES.serviceNotAvailable( "Data-source.xa-config-property", name))); } } } builder.install(); } else { final ModifiableDataSource dataSourceConfig; try { dataSourceConfig = from(context, model); } catch (ValidateException e) { e.printStackTrace(); throw new OperationFailedException( e, new ModelNode() .set( MESSAGES.failedToCreate( "DataSource", operation, e.getLocalizedMessage()))); } final ServiceName dataSourceCongServiceName = DataSourceConfigService.SERVICE_NAME_BASE.append(dsName); final DataSourceConfigService configService = new DataSourceConfigService(dataSourceConfig); final ServiceBuilder<?> builder = serviceTarget.addService(dataSourceCongServiceName, configService); builder.addListener(verificationHandler); for (ServiceName name : serviceNames) { if (dataSourceCongServiceName.append("connetion-properties").isParentOf(name)) { final ServiceController<?> dataSourceController = registry.getService(name); ConnectionPropertiesService connPropService = (ConnectionPropertiesService) dataSourceController.getService(); if (dataSourceController != null) { if (!ServiceController.State.UP.equals(dataSourceController.getState())) { dataSourceController.setMode(ServiceController.Mode.ACTIVE); builder.addDependency( name, String.class, configService.getConnectionPropertyInjector(connPropService.getName())); } else { throw new OperationFailedException( new ModelNode() .set( MESSAGES.serviceAlreadyStarted( "Data-source.connectionProperty", name))); } } else { throw new OperationFailedException( new ModelNode() .set( MESSAGES.serviceNotAvailable( "Data-source.connectionProperty", name))); } } } builder.install(); } context.completeStep(); } }, OperationContext.Stage.RUNTIME); context.addStep( new OperationStepHandler() { public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final ServiceTarget serviceTarget = context.getServiceTarget(); final ServiceVerificationHandler verificationHandler = new ServiceVerificationHandler(); final ModelNode address = operation.require(OP_ADDR); final String dsName = PathAddress.pathAddress(address).getLastElement().getValue(); final String jndiName = model.get(JNDINAME.getName()).asString(); final ServiceRegistry registry = context.getServiceRegistry(true); final ServiceName dataSourceServiceName = AbstractDataSourceService.SERVICE_NAME_BASE.append(dsName); final List<ServiceName> serviceNames = registry.getServiceNames(); final ServiceController<?> dataSourceController = registry.getService(dataSourceServiceName); if (dataSourceController != null) { if (!ServiceController.State.UP.equals(dataSourceController.getState())) { dataSourceController.setMode(ServiceController.Mode.ACTIVE); } else { throw new OperationFailedException( new ModelNode().set(MESSAGES.serviceAlreadyStarted("Data-source", dsName))); } } else { throw new OperationFailedException( new ModelNode().set(MESSAGES.serviceNotAvailable("Data-source", dsName))); } final DataSourceReferenceFactoryService referenceFactoryService = new DataSourceReferenceFactoryService(); final ServiceName referenceFactoryServiceName = DataSourceReferenceFactoryService.SERVICE_NAME_BASE.append(dsName); final ServiceBuilder<?> referenceBuilder = serviceTarget .addService(referenceFactoryServiceName, referenceFactoryService) .addDependency( dataSourceServiceName, javax.sql.DataSource.class, referenceFactoryService.getDataSourceInjector()); referenceBuilder.install(); final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName); final BinderService binderService = new BinderService(bindInfo.getBindName()); final ServiceBuilder<?> binderBuilder = serviceTarget .addService(bindInfo.getBinderServiceName(), binderService) .addDependency( referenceFactoryServiceName, ManagedReferenceFactory.class, binderService.getManagedObjectInjector()) .addDependency( bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector()) .addListener( new AbstractServiceListener<Object>() { public void transition( final ServiceController<? extends Object> controller, final ServiceController.Transition transition) { switch (transition) { case STARTING_to_UP: { SUBSYSTEM_DATASOURCES_LOGGER.boundDataSource(jndiName); break; } case START_REQUESTED_to_DOWN: { SUBSYSTEM_DATASOURCES_LOGGER.unboundDataSource(jndiName); break; } case REMOVING_to_REMOVED: { SUBSYSTEM_DATASOURCES_LOGGER.debugf( "Removed JDBC Data-source [%s]", jndiName); break; } } } }); binderBuilder .setInitialMode(ServiceController.Mode.ACTIVE) .addListener(verificationHandler); binderBuilder.install(); context.completeStep(); } }, OperationContext.Stage.RUNTIME); } context.completeStep(); }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { context.completeStep(); }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (context.getProcessType() == ProcessType.SELF_CONTAINED) { throw ServerLogger.ROOT_LOGGER.cannotAddContentToSelfContainedServer(); } final Resource deploymentResource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); ModelNode contentItemNode = getContentItem(deploymentResource); // Validate this op is available if (!isManaged(contentItemNode)) { throw ServerLogger.ROOT_LOGGER.cannotAddContentToUnmanagedDeployment(); } else if (isArchive(contentItemNode)) { throw ServerLogger.ROOT_LOGGER.cannotAddContentToUnexplodedDeployment(); } final String managementName = context.getCurrentAddress().getLastElement().getValue(); final PathAddress address = PathAddress.pathAddress(DEPLOYMENT, managementName); final byte[] oldHash = CONTENT_HASH.resolveModelAttribute(context, contentItemNode).asBytes(); final boolean overwrite = OVERWRITE.resolveModelAttribute(context, operation).asBoolean(true); List<ModelNode> contents = EXPLODED_CONTENT.resolveModelAttribute(context, operation).asList(); final List<ExplodedContent> addedFiles = new ArrayList<>(contents.size()); final byte[] newHash; if (contents.size() == 1 && contents.get(0).hasDefined(HASH)) { newHash = DeploymentHandlerUtil.addFromHash( contentRepository, contents.get(0), managementName, address, context); if (operation.hasDefined(DeploymentAttributes.UPDATED_PATHS.getName())) { for (ModelNode addedFile : DeploymentAttributes.UPDATED_PATHS.resolveModelAttribute(context, operation).asList()) { addedFiles.add(new ExplodedContent(addedFile.asString())); } } } else { for (ModelNode content : contents) { InputStream in; if (DeploymentHandlerUtils.hasValidContentAdditionParameterDefined(content)) { in = DeploymentHandlerUtils.getInputStream(context, content); } else { in = null; } String path = TARGET_PATH.resolveModelAttribute(context, content).asString(); addedFiles.add(new ExplodedContent(path, in)); } try { newHash = contentRepository.addContentToExploded(oldHash, addedFiles, overwrite); } catch (ExplodedContentException e) { throw createFailureException(e.toString()); } } final List<String> relativePaths = addedFiles.stream().map(ExplodedContent::getRelativePath).collect(Collectors.toList()); contentItemNode.get(CONTENT_HASH.getName()).set(newHash); contentItemNode.get(CONTENT_ARCHIVE.getName()).set(false); if (!addedFiles.isEmpty() && ENABLED.resolveModelAttribute(context, deploymentResource.getModel()).asBoolean()) { context.addStep( new OperationStepHandler() { @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { try { ExecutorService executor = (ExecutorService) context .getServiceRegistry(false) .getRequiredService(JBOSS_SERVER_EXECUTOR) .getValue(); CountDownLatch latch = copy(executor, relativePaths, managementName, newHash); if (latch != null) { try { if (!latch.await(60, TimeUnit.SECONDS)) { return; } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw createFailureException(e.toString()); } } } catch (IOException e) { throw createFailureException(e.toString()); } } }, OperationContext.Stage.RUNTIME); } context.completeStep( new OperationContext.ResultHandler() { @Override public void handleResult( ResultAction resultAction, OperationContext context, ModelNode operation) { if (resultAction == ResultAction.KEEP) { if (oldHash != null && (newHash == null || !Arrays.equals(oldHash, newHash))) { // The old content is no longer used; clean from repos contentRepository.removeContent( ModelContentReference.fromModelAddress(address, oldHash)); } if (newHash != null) { contentRepository.addContentReference( ModelContentReference.fromModelAddress(address, newHash)); } } else if (newHash != null && (oldHash == null || !Arrays.equals(oldHash, newHash))) { // Due to rollback, the new content isn't used; clean from repos contentRepository.removeContent( ModelContentReference.fromModelAddress(address, newHash)); } } }); }
public void execute(OperationContext context, ModelNode operation) { context.readModelForUpdate(PathAddress.EMPTY_ADDRESS).get(ENABLED.getName()).set(true); context.completeStep(); }
@Override public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException { // read /subsystem=jgroups/stack=* for update final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS); final ModelNode subModel = resource.getModel(); // validate the protocol type to be added ModelNode type = ProtocolResource.TYPE.validateOperation(operation); PathElement protocolRelativePath = PathElement.pathElement(ModelKeys.PROTOCOL, type.asString()); // if child resource already exists, throw OFE if (resource.hasChild(protocolRelativePath)) { throw JGroupsMessages.MESSAGES.protocolAlreadyDefined(protocolRelativePath.toString()); } // now get the created model Resource childResource = context.createResource(PathAddress.pathAddress(protocolRelativePath)); final ModelNode protocol = childResource.getModel(); // Process attributes for (final AttributeDefinition attribute : attributes) { // we use PROPERTIES only to allow the user to pass in a list of properties on store add // commands // don't copy these into the model if (attribute.getName().equals(ModelKeys.PROPERTIES)) continue; attribute.validateAndSet(operation, protocol); } // get the current list of protocol names and add the new protocol // this list is used to maintain order ModelNode protocols = subModel.get(ModelKeys.PROTOCOLS); if (!protocols.isDefined()) { protocols.setEmptyList(); } protocols.add(type); // Process type specific properties if required process(subModel, operation); // The protocol parameters <property name=>value</property> if (operation.hasDefined(ModelKeys.PROPERTIES)) { for (Property property : operation.get(ModelKeys.PROPERTIES).asPropertyList()) { // create a new property=name resource final Resource param = context.createResource( PathAddress.pathAddress( protocolRelativePath, PathElement.pathElement(ModelKeys.PROPERTY, property.getName()))); final ModelNode value = property.getValue(); if (!value.isDefined()) { throw JGroupsMessages.MESSAGES.propertyNotDefined( property.getName(), protocolRelativePath.toString()); } // set the value of the property param.getModel().get(ModelDescriptionConstants.VALUE).set(value); } } // This needs a reload reloadRequiredStep(context); context.completeStep(); }
@Override protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException { // get the channel name and channel attribute PathAddress pathAddress = PathAddress.pathAddress(operation.require(OP_ADDR)); String channelName = pathAddress.getElement(pathAddress.size() - 1).getValue(); String attrName = operation.require(NAME).asString(); ChannelMetrics metric = ChannelMetrics.getStat(attrName); // lookup the channel ServiceName channelServiceName = ChannelInstanceResource.CHANNEL_PARENT.append(channelName); ServiceController<?> controller = context.getServiceRegistry(false).getService(channelServiceName); // check that the service has been installed and started boolean started = controller != null && controller.getValue() != null; ModelNode result = new ModelNode(); if (metric == null) { context.getFailureDescription().set(JGroupsMessages.MESSAGES.unknownMetric(attrName)); } else if (!started) { // when the cache service is not available, return a null result } else { JChannel channel = (JChannel) controller.getValue(); switch (metric) { case ADDRESS: result.set(channel.getAddressAsString()); break; case ADDRESS_AS_UUID: result.set(channel.getAddressAsUUID()); break; case DISCARD_OWN_MESSAGES: result.set(channel.getDiscardOwnMessages()); break; case NUM_TASKS_IN_TIMER: result.set(channel.getNumberOfTasksInTimer()); break; case NUM_TIMER_THREADS: result.set(channel.getTimerThreads()); break; case RECEIVED_BYTES: result.set(channel.getReceivedBytes()); break; case RECEIVED_MESSAGES: result.set(channel.getReceivedMessages()); break; case SENT_BYTES: result.set(channel.getSentBytes()); break; case SENT_MESSAGES: result.set(channel.getSentMessages()); break; case STATE: result.set(channel.getState()); break; case STATS_ENABLED: result.set(channel.statsEnabled()); break; case VERSION: result.set(JChannel.getVersion()); break; case VIEW: result.set(channel.getViewAsString()); break; } context.getResult().set(result); } context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER); }