Java Code Examples for org.jboss.as.controller.OperationContext

The following are top voted examples for showing how to use org.jboss.as.controller.OperationContext. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: switchyard   File: SwitchYardModuleAdd.java   Source Code and License 8 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model,
                              ServiceVerificationHandler verificationHandler, List<ServiceController<?>> newControllers) throws OperationFailedException {
    final String moduleId = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement().getValue();
    _componentNames.add(moduleId);

    context.addStep(new AbstractDeploymentChainStep() {
        protected void execute(DeploymentProcessorTarget processorTarget) {
            processorTarget.addDeploymentProcessor(SwitchYardExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, _priority++, new SwitchYardModuleDependencyProcessor(moduleId));
        }
    }, OperationContext.Stage.RUNTIME);

    final SwitchYardComponentService componentService = new SwitchYardComponentService(moduleId, model);
    final ServiceBuilder<Component> componentServiceBuilder = context.getServiceTarget().addService(SwitchYardComponentService.SERVICE_NAME.append(moduleId), componentService);
    componentServiceBuilder.addDependency(SwitchYardInjectorService.SERVICE_NAME, Map.class, componentService.getInjectedValues())
            .addDependency(RA_REPOSITORY_SERVICE_NAME, ResourceAdapterRepository.class, componentService.getResourceAdapterRepository());
    componentServiceBuilder.addDependency(WebSubsystemServices.JBOSS_WEB);
    componentServiceBuilder.setInitialMode(Mode.ACTIVE);
    newControllers.add(componentServiceBuilder.install());
}
 
Example 2
Project: wildfly-microprofile-config   File: SubsystemAdd.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {

    MicroProfileConfigLogger.ROOT_LOGGER.activatingSubsystem();

    ConfigProviderService.install(context);

    //Add deployment processors here
    //Remove this if you don't need to hook into the deployers, or you can add as many as you like
    //see SubDeploymentProcessor for explanation of the phases
    context.addStep(new AbstractDeploymentChainStep() {
        public void execute(DeploymentProcessorTarget processorTarget) {
            processorTarget.addDeploymentProcessor(SubsystemExtension.SUBSYSTEM_NAME, DependencyProcessor.PHASE, DependencyProcessor.PRIORITY, new DependencyProcessor());
            processorTarget.addDeploymentProcessor(SubsystemExtension.SUBSYSTEM_NAME, SubsystemDeploymentProcessor.PHASE, SubsystemDeploymentProcessor.PRIORITY, new SubsystemDeploymentProcessor());

        }
    }, OperationContext.Stage.RUNTIME);

}
 
Example 3
Project: wildfly-nosql   File: Neo4jDriverSubsystemAdd.java   Source Code and License 6 votes vote down vote up
protected void performBoottime(final OperationContext context, final ModelNode operation, final ModelNode model) throws
        OperationFailedException {

    runtimeValidator.validate(operation.resolve());
    context.addStep(new AbstractDeploymentChainStep() {
        protected void execute(DeploymentProcessorTarget processorTarget) {
            final int PARSE_NEO4J_DRIVER                          = 0x4C00;
            final int DEPENDENCIES_NEO4J_DRIVER                   = 0x1F10;
            // TODO: use Phase.PARSE_NEO4J_DRIVER
            processorTarget.addDeploymentProcessor(Neo4jDriverExtension.SUBSYSTEM_NAME, Phase.PARSE, PARSE_NEO4J_DRIVER, new DriverScanDependencyProcessor("neo4jsubsystem"));
            // TODO: use Phase.DEPENDENCIES_NEO4J_DRIVER
            processorTarget.addDeploymentProcessor(Neo4jDriverExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, DEPENDENCIES_NEO4J_DRIVER, DriverDependencyProcessor.getInstance());
        }
    }, OperationContext.Stage.RUNTIME);

    startNeo4jDriverSubsysteService(context);

}
 
Example 4
Project: wildfly-nosql   File: Neo4jDefinition.java   Source Code and License 6 votes vote down vote up
private void startNeo4jDriverService(OperationContext context, ConfigurationBuilder builder, final Set<String> outboundSocketBindings) throws OperationFailedException {
    if (builder.getJNDIName() != null && builder.getJNDIName().length() > 0) {
        final Neo4jClientConnectionService neo4jClientConnectionService = new Neo4jClientConnectionService(builder);
        final ServiceName serviceName = ConnectionServiceAccess.serviceName(builder.getDescription());
        final ContextNames.BindInfo bindingInfo = ContextNames.bindInfoFor(builder.getJNDIName());

        final BinderService binderService = new BinderService(bindingInfo.getBindName());
        context.getServiceTarget().addService(bindingInfo.getBinderServiceName(), binderService)
                .addDependency(Neo4jSubsystemService.serviceName())
                .addDependency(bindingInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector())
                .addDependency(serviceName, Neo4jClientConnectionService.class, new Injector<Neo4jClientConnectionService>() {
                    @Override
                    public void inject(final Neo4jClientConnectionService value) throws
                            InjectionException {
                        binderService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new ImmediateValue<>(value.getDriver())));
                    }

                    @Override
                    public void uninject() {
                        binderService.getNamingStoreInjector().uninject();
                    }
                }).install();

        final ServiceBuilder<Neo4jClientConnectionService> serviceBuilder = context.getServiceTarget().addService(serviceName, neo4jClientConnectionService);
        serviceBuilder.addDependency(Neo4jSubsystemService.serviceName(), new CastingInjector<>(neo4jClientConnectionService.getNeo4jSubsystemServiceInjectedValue(), Neo4jSubsystemService.class));
        // add service dependency on each separate hostname/port reference in standalone*.xml referenced from this driver profile definition.
        for (final String outboundSocketBinding : outboundSocketBindings) {
            final ServiceName outboundSocketBindingDependency = context.getCapabilityServiceName(Neo4jDriverDefinition.OUTBOUND_SOCKET_BINDING_CAPABILITY_NAME, outboundSocketBinding, OutboundSocketBinding.class);
            serviceBuilder.addDependency(ServiceBuilder.DependencyType.REQUIRED, outboundSocketBindingDependency, OutboundSocketBinding.class, neo4jClientConnectionService.getOutboundSocketBindingInjector(outboundSocketBinding));
        }
        if (builder.getSecurityDomain() != null) {
            serviceBuilder.addDependency(SubjectFactoryService.SERVICE_NAME, SubjectFactory.class,
                    neo4jClientConnectionService.getSubjectFactoryInjector());
        }

        serviceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    }
}
 
Example 5
Project: wildfly-nosql   File: OrientDefinition.java   Source Code and License 6 votes vote down vote up
private void startServices(OperationContext context, Configuration configuration, String outboundSocketBinding) {
    ServiceName connectionsServiceName = ConnectionServiceAccess.serviceName(configuration.getProfileName());
    OrientInteraction orientInteraction = new OrientInteraction(configuration);
    OrientClientConnectionsService connectionsService = new OrientClientConnectionsService(configuration, orientInteraction);
    ServiceBuilder<OrientClientConnectionsService> connectionsServiceBuilder = context.getServiceTarget()
            .addService(connectionsServiceName, connectionsService);

    connectionsServiceBuilder.addDependency(OrientSubsystemService.SERVICE_NAME, new CastingInjector<>(
            connectionsService.getOrientSubsystemServiceInjectedValue(), OrientSubsystemService.class));

    ServiceName outboundSocketBindingServiceName = context.getCapabilityServiceName(
            OrientDriverDefinition.OUTBOUND_SOCKET_BINDING_CAPABILITY_NAME, outboundSocketBinding,
            OutboundSocketBinding.class);
    connectionsServiceBuilder.addDependency(ServiceBuilder.DependencyType.REQUIRED, outboundSocketBindingServiceName,
            new CastingInjector<>(connectionsService.getOutboundSocketBindingInjectedValue(),
                    OutboundSocketBinding.class));
    if (configuration.getSecurityDomain() != null) {
        connectionsServiceBuilder.addDependency(SubjectFactoryService.SERVICE_NAME, SubjectFactory.class,
                connectionsService.getSubjectFactoryInjector());
    }

    connectionsServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
    bindJndi(context, connectionsServiceName, configuration.getJndiName(), orientInteraction.getDatabasePoolClass());
}
 
Example 6
Project: wildfly-nosql   File: OrientDefinition.java   Source Code and License 6 votes vote down vote up
private <T> void bindJndi(OperationContext context, ServiceName serviceName, String jndiName, Class<T> clazz) {
    ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
    BinderService binderService = new BinderService(bindInfo.getBindName());
    context.getServiceTarget().addService(bindInfo.getBinderServiceName(), binderService)
            .addDependency(OrientSubsystemService.SERVICE_NAME)
            .addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class,
                    binderService.getNamingStoreInjector())
            .addDependency(serviceName, OrientClientConnectionsService.class,
                    new Injector<OrientClientConnectionsService>() {
                        @Override
                        public void inject(final OrientClientConnectionsService value) throws InjectionException {
                            binderService.getManagedObjectInjector().inject(
                                    new ValueManagedReferenceFactory(new ImmediateValue<>(value.unwrap(clazz))));
                        }

                        @Override
                        public void uninject() {
                            binderService.getNamingStoreInjector().uninject();
                        }
                    })
            .install();
}
 
Example 7
Project: wildfly-nosql   File: OrientDriverSubsystemAdd.java   Source Code and License 6 votes vote down vote up
protected void performBoottime(final OperationContext context, final ModelNode operation, final ModelNode model)
        throws OperationFailedException {
    runtimeValidator.validate(operation.resolve());
    context.addStep(new AbstractDeploymentChainStep() {
        protected void execute(DeploymentProcessorTarget processorTarget) {
            final int PARSE_ORIENT_DRIVER                         = 0x4C01;
            final int DEPENDENCIES_ORIENT_DRIVER                  = 0x1F11;
            // TODO: use Phase.PARSE_ORIENT_DRIVER
            processorTarget.addDeploymentProcessor(OrientDriverExtension.SUBSYSTEM_NAME, Phase.PARSE,
                    PARSE_ORIENT_DRIVER, new DriverScanDependencyProcessor("orientdbsubsystem"));
            // TODO: use Phase.DEPENDENCIES_ORIENT_DRIVER
            processorTarget.addDeploymentProcessor(OrientDriverExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES,
                    DEPENDENCIES_ORIENT_DRIVER, DriverDependencyProcessor.getInstance());
        }
    }, OperationContext.Stage.RUNTIME);

    startOrientSubsystemService(context);
}
 
Example 8
Project: wildfly-nosql   File: CassandraDriverSubsystemAdd.java   Source Code and License 6 votes vote down vote up
protected void performBoottime(final OperationContext context, final ModelNode operation, final ModelNode model) throws
        OperationFailedException {

    runtimeValidator.validate(operation.resolve());
    context.addStep(new AbstractDeploymentChainStep() {
        protected void execute(DeploymentProcessorTarget processorTarget) {
            final int PARSE_CASSANDRA_DRIVER                      = 0x4C02;
            final int DEPENDENCIES_CASSANDRA_DRIVER               = 0x1F12;
            // TODO: use Phase.PARSE_CASSANDRA_DRIVER
            processorTarget.addDeploymentProcessor(CassandraDriverExtension.SUBSYSTEM_NAME, Phase.PARSE, PARSE_CASSANDRA_DRIVER, new DriverScanDependencyProcessor("cassandrasubsystem"));
            // TODO: use Phase.DEPENDENCIES_CASSANDRA_DRIVER
            processorTarget.addDeploymentProcessor(CassandraDriverExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, DEPENDENCIES_CASSANDRA_DRIVER, DriverDependencyProcessor.getInstance());
        }
    }, OperationContext.Stage.RUNTIME);

    startCassandraDriverSubsysteService(context);
}
 
Example 9
Project: wildfly-nosql   File: MongoDriverSubsystemAdd.java   Source Code and License 6 votes vote down vote up
protected void performBoottime(final OperationContext context, final ModelNode operation, final ModelNode model) throws
        OperationFailedException {

    runtimeValidator.validate(operation.resolve());
    context.addStep(new AbstractDeploymentChainStep() {
        protected void execute(DeploymentProcessorTarget processorTarget) {
            final int PARSE_MONGO_DRIVER                          = 0x4C03;
            final int DEPENDENCIES_MONGO_DRIVER                   = 0x1F13;
            // TODO: use Phase.PARSE_MONGO_DRIVER
            processorTarget.addDeploymentProcessor(MongoDriverExtension.SUBSYSTEM_NAME, Phase.PARSE, PARSE_MONGO_DRIVER, new DriverScanDependencyProcessor("mongodbsubsystem"));
            // TODO: use Phase.DEPENDENCIES_MONGO_DRIVER
            processorTarget.addDeploymentProcessor(MongoDriverExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, DEPENDENCIES_MONGO_DRIVER, DriverDependencyProcessor.getInstance());
        }
    }, OperationContext.Stage.RUNTIME);

    startMongoDriverSubsysteService(context);
}
 
Example 10
Project: smpp-extensions   File: SubsystemAdd.java   Source Code and License 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void performBoottime(OperationContext context, ModelNode operation, ModelNode model,
        ServiceVerificationHandler verificationHandler, List<ServiceController<?>> newControllers)
        throws OperationFailedException {

    ModelNode fullModel = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));

    SmppService service = SmppService.INSTANCE;
    service.setModel(fullModel);

    ServiceName name = SmppService.getServiceName();
    ServiceController<SmppServiceInterface> controller = context.getServiceTarget()
            .addService(name, service)
            .addDependency(PathManagerService.SERVICE_NAME, PathManager.class, service.getPathManagerInjector())
            .addDependency(MBeanServerService.SERVICE_NAME, MBeanServer.class, service.getMbeanServer())
            .addListener(verificationHandler)
            .setInitialMode(ServiceController.Mode.ACTIVE)
            .install();
    newControllers.add(controller);

}
 
Example 11
Project: jam-metrics   File: JamMetricsSubsystemAdd.java   Source Code and License 6 votes vote down vote up
@Override
protected void performBoottime(OperationContext context, ModelNode operation, final ModelNode model) throws OperationFailedException {

    context.addStep(new AbstractDeploymentChainStep() {
        @Override
        protected void execute(DeploymentProcessorTarget processorTarget) {
        //    processorTarget.addDeploymentProcessor(jam-metricsExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_AUTOMATED_METRICS, new jam-metricsDependencyProcessor());
            processorTarget.addDeploymentProcessor(JamMetricsExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_METRIC, new JamMetricsDependencyProcessor());
            //    processorTarget.addDeploymentProcessor(jam-metricsExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_METRIC, new jam-metricsInterceptorProcessor());
            processorTarget.addDeploymentProcessor(JamMetricsExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_METRIC_VALIDATOR_FACTORY, new JamMetricsBeanValidationFactoryProcessor());
        }
    }, OperationContext.Stage.RUNTIME);
    //  jam-metricsLogger.ROOT_LOGGER.startedjam-metricsSubsystem();

    /*    ServiceTarget target = context.getServiceTarget();
     target.addService(jam-metricsServices.AUTOMATED_METRICS, new jam-metricsServices())
     .setInitialMode(ServiceController.Mode.ACTIVE)
     .install();*/
}
 
Example 12
Project: hawkular-commons   File: NestSubsystemStart.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(OperationContext opContext, ModelNode model) throws OperationFailedException {
    try {
        ServiceName name = NestService.SERVICE_NAME;
        NestService service = (NestService) opContext.getServiceRegistry(true).getRequiredService(name).getValue();

        boolean restart = model.get(NestSubsystemDefinition.START_OP_PARAM_RESTART.getName()).asBoolean(false);
        if (restart) {
            log.debug("Asked to restart the nest. Will stop it, then restart it now.");
            service.stopNest();
        }
        service.startNest();
    } catch (ServiceNotFoundException snfe) {
        throw new OperationFailedException("Cannot restart nest - the nest is disabled", snfe);
    } catch (Exception e) {
        throw new OperationFailedException("Cannot restart nest", e);
    }

    opContext.stepCompleted();
    return;
}
 
Example 13
Project: hawkular-commons   File: NestSubsystemStop.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(OperationContext opContext, ModelNode model) throws OperationFailedException {
    log.debug("Asked to stop the nest");

    NestService service = null;

    try {
        ServiceName name = NestService.SERVICE_NAME;
        service = (NestService) opContext.getServiceRegistry(true).getRequiredService(name).getValue();
    } catch (Exception e) {
        // The nest service just isn't deployed, so obviously, it is already stopped. Just keep going.
    }

    if (service != null) {
        service.stopNest();
    }

    opContext.stepCompleted();
    return;
}
 
Example 14
Project: teiid   File: TransportRemove.java   Source Code and License 6 votes vote down vote up
@Override
  protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) {

      final ModelNode address = operation.require(OP_ADDR);
      final PathAddress pathAddress = PathAddress.pathAddress(address);

  	String transportName = pathAddress.getLastElement().getValue();

  	final ServiceRegistry serviceRegistry = context.getServiceRegistry(true);
  	
  	ServiceName serviceName = TeiidServiceNames.transportServiceName(transportName);
final ServiceController<?> controller = serviceRegistry.getService(serviceName);
if (controller != null) {
	TransportService transport = TransportService.class.cast(controller.getValue());
	
	if (transport.isEmbedded()) {
		final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(LocalServerConnection.jndiNameForRuntime(transportName));
		context.removeService(bindInfo.getBinderServiceName());
		context.removeService(TeiidServiceNames.embeddedTransportServiceName(transportName).append("reference-factory")); //$NON-NLS-1$
	}
	context.removeService(serviceName);
}
  }
 
Example 15
Project: teiid   File: TeiidOperationHandler.java   Source Code and License 6 votes vote down vote up
@Override
protected void executeOperation(OperationContext context, DQPCore engine, ModelNode operation) throws OperationFailedException{
	if (!operation.hasDefined(OperationsConstants.SESSION.getName())) {
		throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.SESSION.getName()+MISSING)));
	}
	boolean includeSourceQueries = true;
	if (operation.hasDefined(OperationsConstants.INCLUDE_SOURCE.getName())) {
		includeSourceQueries = operation.get(OperationsConstants.INCLUDE_SOURCE.getName()).asBoolean();
	}
	ModelNode result = context.getResult();
	List<RequestMetadata> requests = engine.getRequestsForSession(operation.get(OperationsConstants.SESSION.getName()).asString());
	for (RequestMetadata request:requests) {
		if (request.sourceRequest()) {
			if (includeSourceQueries) {
				VDBMetadataMapper.RequestMetadataMapper.INSTANCE.wrap(request, result.add());
			}
		}
		else {
			VDBMetadataMapper.RequestMetadataMapper.INSTANCE.wrap(request, result.add());
		}
	}
}
 
Example 16
Project: teiid   File: TeiidOperationHandler.java   Source Code and License 6 votes vote down vote up
@Override
protected void executeOperation(OperationContext context, DQPCore engine, ModelNode operation) throws OperationFailedException{
	boolean includeSourceQueries = true;
	if (operation.hasDefined(OperationsConstants.INCLUDE_SOURCE.getName())) {
		includeSourceQueries = operation.get(OperationsConstants.INCLUDE_SOURCE.getName()).asBoolean();
	}

	ModelNode result = context.getResult();
	List<RequestMetadata> requests = engine.getRequests();
	for (RequestMetadata request:requests) {
		if (request.sourceRequest()) {
			if (includeSourceQueries) {
				VDBMetadataMapper.RequestMetadataMapper.INSTANCE.wrap(request, result.add());
			}
		}
		else {
			VDBMetadataMapper.RequestMetadataMapper.INSTANCE.wrap(request, result.add());
		}
	}
}
 
Example 17
Project: teiid   File: TeiidOperationHandler.java   Source Code and License 6 votes vote down vote up
@Override
protected void executeOperation(OperationContext context, DQPCore engine, ModelNode operation) throws OperationFailedException{
	try {
		if (!operation.hasDefined(OperationsConstants.SESSION.getName())) {
			throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.SESSION.getName()+MISSING)));
		}
		if (!operation.hasDefined(OperationsConstants.EXECUTION_ID.getName())) {
			throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.EXECUTION_ID.getName()+MISSING)));
		}
		boolean pass = engine.cancelRequest(operation.get(OperationsConstants.SESSION.getName()).asString(), operation.get(OperationsConstants.EXECUTION_ID.getName()).asLong());
		ModelNode result = context.getResult();

		result.set(pass);
	} catch (TeiidComponentException e) {
		throw new OperationFailedException(e, new ModelNode().set(e.getMessage()));
	}
}
 
Example 18
Project: teiid   File: TeiidOperationHandler.java   Source Code and License 6 votes vote down vote up
@Override
protected SessionAwareCache getService(OperationContext context, PathAddress pathAddress, ModelNode operation) throws OperationFailedException {
	String cacheType = Admin.Cache.QUERY_SERVICE_RESULT_SET_CACHE.name();

	if (operation.hasDefined(OperationsConstants.CACHE_TYPE.getName())) {
		cacheType = operation.get(OperationsConstants.CACHE_TYPE.getName()).asString();
	}

	ServiceController<?> sc;
	if (SessionAwareCache.isResultsetCache(cacheType)) {
		sc = context.getServiceRegistry(false).getRequiredService(TeiidServiceNames.CACHE_RESULTSET);
	}
	else {
		sc = context.getServiceRegistry(false).getRequiredService(TeiidServiceNames.CACHE_PREPAREDPLAN);
	}

	if (sc != null) {
		return SessionAwareCache.class.cast(sc.getValue());
	}
	return null;
}
 
Example 19
Project: teiid   File: TeiidOperationHandler.java   Source Code and License 6 votes vote down vote up
@Override
protected void executeOperation(OperationContext context, SessionAwareCache cache, ModelNode operation) throws OperationFailedException {
	if (!operation.hasDefined(OperationsConstants.CACHE_TYPE.getName())) {
		throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.CACHE_TYPE.getName()+MISSING)));
	}

	String cacheType = operation.get(OperationsConstants.CACHE_TYPE.getName()).asString();
	if (cache == null) {
		throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50071, cacheType)));
	}

	if (operation.hasDefined(OperationsConstants.VDB_NAME.getName()) && operation.hasDefined(OperationsConstants.VDB_VERSION.getName())) {
		String vdbName = operation.get(OperationsConstants.VDB_NAME.getName()).asString();
		int vdbVersion = operation.get(OperationsConstants.VDB_VERSION.getName()).asInt();
		TeiidOperationHandler.checkVDB(context, vdbName, vdbVersion);
		LogManager.logInfo(LogConstants.CTX_DQP, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50005, cacheType, vdbName, vdbVersion));
		cache.clearForVDB(vdbName, vdbVersion);
	}
	else {
		LogManager.logInfo(LogConstants.CTX_DQP, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50098, cacheType));
		cache.clearAll();
	}
}
 
Example 20
Project: teiid   File: TeiidOperationHandler.java   Source Code and License 6 votes vote down vote up
@Override
protected void executeOperation(OperationContext context, DQPCore engine, ModelNode operation) throws OperationFailedException {

	if (!operation.hasDefined(OperationsConstants.VDB_NAME.getName())) {
		throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.VDB_NAME.getName()+MISSING)));
	}
	if (!operation.hasDefined(OperationsConstants.VDB_VERSION.getName())) {
		throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.VDB_VERSION.getName()+MISSING)));
	}
	if (!operation.hasDefined(OperationsConstants.SQL_QUERY.getName())) {
		throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.SQL_QUERY.getName()+MISSING)));
	}
	if (!operation.hasDefined(OperationsConstants.TIMEOUT_IN_MILLI.getName())) {
		throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.TIMEOUT_IN_MILLI.getName()+MISSING)));
	}

	ModelNode result = context.getResult();
	String vdbName = operation.get(OperationsConstants.VDB_NAME.getName()).asString();
	int vdbVersion = operation.get(OperationsConstants.VDB_VERSION.getName()).asInt();
	String sql = operation.get(OperationsConstants.SQL_QUERY.getName()).asString();
	int timeout = operation.get(OperationsConstants.TIMEOUT_IN_MILLI.getName()).asInt();

	VDBMetaData vdb = checkVDB(context, vdbName, vdbVersion);

	result.set(executeQuery(vdb, engine, sql, timeout, new ModelNode(), true));
}
 
Example 21
Project: teiid   File: TeiidOperationHandler.java   Source Code and License 6 votes vote down vote up
@Override
protected void executeOperation(OperationContext context, VDBRepository repo, ModelNode operation) throws OperationFailedException {
	if (!operation.hasDefined(OperationsConstants.VDB_NAME.getName())) {
		throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.VDB_NAME.getName()+MISSING)));
	}
	if (!operation.hasDefined(OperationsConstants.VDB_VERSION.getName())) {
		throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.VDB_VERSION.getName()+MISSING)));
	}

	ModelNode result = context.getResult();
	String vdbName = operation.get(OperationsConstants.VDB_NAME.getName()).asString();
	int vdbVersion = operation.get(OperationsConstants.VDB_VERSION.getName()).asInt();

	VDBMetaData vdb = repo.getVDB(vdbName, vdbVersion);
	if (vdb != null) {
		VDBMetadataMapper.INSTANCE.wrap(vdb, result);
	}
	else {
		throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50096, vdbName, vdbVersion)));
	}
}
 
Example 22
Project: teiid   File: TeiidOperationHandler.java   Source Code and License 6 votes vote down vote up
@Override
public RuntimeVDB getService(OperationContext context, PathAddress pathAddress, ModelNode operation) throws OperationFailedException {
	if (!operation.hasDefined(OperationsConstants.VDB_NAME.getName())) {
		throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.VDB_NAME.getName()+MISSING)));
	}

	if (!operation.hasDefined(OperationsConstants.VDB_VERSION.getName())) {
		throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.VDB_VERSION.getName()+MISSING)));
	}

	String vdbName = operation.get(OperationsConstants.VDB_NAME.getName()).asString();
	int vdbVersion = operation.get(OperationsConstants.VDB_VERSION.getName()).asInt();

	TeiidOperationHandler.checkVDB(context, vdbName, vdbVersion);

	ServiceController<?> sc = context.getServiceRegistry(this.changesRuntimeState).getRequiredService(TeiidServiceNames.vdbServiceName(vdbName, vdbVersion));
       return RuntimeVDB.class.cast(sc.getValue());
}
 
Example 23
Project: teiid   File: TeiidOperationHandler.java   Source Code and License 6 votes vote down vote up
static void updateServices(OperationContext context, RuntimeVDB vdb,
			String dsName, ReplaceResult rr) {
	if (rr.isNew) {
		VDBDeployer.addDataSourceListener(context.getServiceTarget(), new VDBKey(vdb.getVdb().getName(), vdb.getVdb().getVersion()), dsName);
	}
	if (rr.removedDs != null) {
		final ServiceRegistry registry = context.getServiceRegistry(true);
	    ServiceName serviceName;
		try {
			serviceName = TeiidServiceNames.dsListenerServiceName(vdb.getVdb().getName(), vdb.getVdb().getVersion(), rr.removedDs);
		} catch (InvalidServiceNameException e) {
			return; //the old isn't valid
		}
	    final ServiceController<?> controller = registry.getService(serviceName);
	    if (controller != null) {
	    	context.removeService(serviceName);
	    }
	}
}
 
Example 24
Project: teiid   File: TeiidOperationHandler.java   Source Code and License 6 votes vote down vote up
@Override
protected void executeOperation(OperationContext context, RuntimeVDB vdb, ModelNode operation) throws OperationFailedException {
	if (!operation.hasDefined(OperationsConstants.DATA_ROLE.getName())) {
		throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.DATA_ROLE.getName()+MISSING)));
	}

	if (!operation.hasDefined(OperationsConstants.MAPPED_ROLE.getName())) {
		throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.MAPPED_ROLE.getName()+MISSING)));
	}

	String policyName = operation.get(OperationsConstants.DATA_ROLE.getName()).asString();
	String mappedRole = operation.get(OperationsConstants.MAPPED_ROLE.getName()).asString();

	try {
		vdb.addDataRole(policyName, mappedRole);
	} catch (AdminProcessingException e) {
		throw new OperationFailedException(new ModelNode().set(e.getMessage()));
	}
}
 
Example 25
Project: teiid   File: TeiidOperationHandler.java   Source Code and License 6 votes vote down vote up
@Override
protected void executeOperation(OperationContext context, RuntimeVDB vdb, ModelNode operation) throws OperationFailedException {
	if (!operation.hasDefined(OperationsConstants.DATA_ROLE.getName())) {
		throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.DATA_ROLE.getName()+MISSING)));
	}

	if (!operation.hasDefined(OperationsConstants.MAPPED_ROLE.getName())) {
		throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.MAPPED_ROLE.getName()+MISSING)));
	}

	String policyName = operation.get(OperationsConstants.DATA_ROLE.getName()).asString();
	String mappedRole = operation.get(OperationsConstants.MAPPED_ROLE.getName()).asString();

	try {
		vdb.remoteDataRole(policyName, mappedRole);
	} catch (AdminProcessingException e) {
		throw new OperationFailedException(new ModelNode().set(e.getMessage()));
	}
}
 
Example 26
Project: teiid   File: TeiidOperationHandler.java   Source Code and License 6 votes vote down vote up
@Override
protected void executeOperation(OperationContext context, RuntimeVDB vdb, ModelNode operation) throws OperationFailedException {
	List<String> models = new ArrayList<String>();
	if (operation.hasDefined(OperationsConstants.MODEL_NAMES.getName())) {
		String modelNames = operation.get(OperationsConstants.MODEL_NAMES.getName()).asString();
		for (String model:modelNames.split(",")) { //$NON-NLS-1$
			models.add(model.trim());
		}
	}

	try {
		vdb.restart(models);
	} catch (AdminProcessingException e) {
		throw new OperationFailedException(new ModelNode().set(e.getMessage()));
	}
}
 
Example 27
Project: teiid   File: TeiidOperationHandler.java   Source Code and License 6 votes vote down vote up
@Override
protected void executeOperation(OperationContext context, RuntimeVDB vdb, ModelNode operation) throws OperationFailedException {
	if (!operation.hasDefined(OperationsConstants.MODEL_NAME.getName())) {
		throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.MODEL_NAME.getName()+MISSING)));
	}
	
	if (!operation.hasDefined(OperationsConstants.SOURCE_NAME.getName())) {
		throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.SOURCE_NAME.getName()+MISSING)));
	}

	String modelName = operation.get(OperationsConstants.MODEL_NAME.getName()).asString();
	String sourceName = operation.get(OperationsConstants.SOURCE_NAME.getName()).asString();

	try {
		synchronized (vdb.getVdb()) {
			ReplaceResult rr = vdb.removeSource(modelName, sourceName);
			updateServices(context, vdb, null, rr);
		}
	} catch (AdminProcessingException e) {
		throw new OperationFailedException(new ModelNode().set(e.getMessage()));
	}
}
 
Example 28
Project: teiid   File: TeiidOperationHandler.java   Source Code and License 6 votes vote down vote up
@Override
protected void executeOperation(OperationContext context, TranslatorRepository repo, ModelNode operation) throws OperationFailedException {

	if (!operation.hasDefined(OperationsConstants.TRANSLATOR_NAME.getName())) {
		throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.TRANSLATOR_NAME.getName()+MISSING)));
	}
	
       if (!operation.hasDefined(OperationsConstants.PROPERTY_TYPE.getName())) {
           throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString(OperationsConstants.PROPERTY_TYPE.getName()+MISSING)));
       }		

	ModelNode result = context.getResult();
	String translatorName = operation.get(OperationsConstants.TRANSLATOR_NAME.getName()).asString();
	PropertyType type = PropertyType.valueOf(operation.get(OperationsConstants.PROPERTY_TYPE.getName()).asString().toUpperCase());		
	VDBTranslatorMetaData translator = repo.getTranslatorMetaData(translatorName);
	if (translator != null) {
		ExtendedPropertyMetadataList properties = translator.getAttachment(ExtendedPropertyMetadataList.class);
		for (ExtendedPropertyMetadata epm:properties) {
		    if (PropertyType.valueOf(epm.category()).equals(type)) {
		        result.add(buildNode(epm));
		    }
		}
	}
}
 
Example 29
Project: teiid   File: TeiidOperationHandler.java   Source Code and License 6 votes vote down vote up
@Override
protected void executeOperation(OperationContext context, DQPCore engine, ModelNode operation) throws OperationFailedException{
	EngineStatisticsMetadata stats = new EngineStatisticsMetadata();
	try {
		BufferManagerService bufferMgrSvc = getBufferManager(context);
		stats.setSessionCount(getSessionCount(context));
		stats.setTotalMemoryUsedInKB(bufferMgrSvc.getHeapCacheMemoryInUseKB());
		stats.setMemoryUsedByActivePlansInKB(bufferMgrSvc.getHeapMemoryInUseByActivePlansKB());
		stats.setDiskWriteCount(bufferMgrSvc.getDiskWriteCount());
		stats.setDiskReadCount(bufferMgrSvc.getDiskReadCount());
		stats.setCacheReadCount(bufferMgrSvc.getCacheReadCount());
		stats.setCacheWriteCount(bufferMgrSvc.getCacheWriteCount());
		stats.setDiskSpaceUsedInMB(bufferMgrSvc.getUsedDiskBufferSpaceMB());
		stats.setActivePlanCount(engine.getActivePlanCount());
		stats.setWaitPlanCount(engine.getWaitingPlanCount());
		stats.setMaxWaitPlanWaterMark(engine.getMaxWaitingPlanWatermark());
		VDBMetadataMapper.EngineStatisticsMetadataMapper.INSTANCE.wrap(stats, context.getResult());
	} catch (AdminException e) {
		throw new OperationFailedException(new ModelNode().set(e.getMessage()));
	}
}
 
Example 30
Project: teiid   File: TeiidRemove.java   Source Code and License 6 votes vote down vote up
@Override
  protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) {

context.removeService(TeiidServiceNames.PREPAREDPLAN_CACHE_FACTORY);
context.removeService(TeiidServiceNames.RESULTSET_CACHE_FACTORY);
context.removeService(TeiidServiceNames.AUTHORIZATION_VALIDATOR);
context.removeService(TeiidServiceNames.PREPARSER);
context.removeService(TeiidServiceNames.EVENT_DISTRIBUTOR_FACTORY);

context.removeService(TeiidServiceNames.ENGINE);
context.removeService(TeiidServiceNames.CACHE_PREPAREDPLAN);
context.removeService(TeiidServiceNames.CACHE_RESULTSET);
context.removeService(TeiidServiceNames.TUPLE_BUFFER);
context.removeService(TeiidServiceNames.BUFFER_MGR);
context.removeService(TeiidServiceNames.BUFFER_DIR);
context.removeService(TeiidServiceNames.OBJECT_SERIALIZER);
context.removeService(TeiidServiceNames.VDB_STATUS_CHECKER);
context.removeService(TeiidServiceNames.VDB_REPO);
context.removeService(TeiidServiceNames.TRANSLATOR_REPO);
  }
 
Example 31
Project: switchyard   File: SwitchYardModuleAdd.java   Source Code and License 6 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final String moduleId = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement().getValue();
    _componentNames.add(moduleId);

    context.addStep(new AbstractDeploymentChainStep() {
        protected void execute(DeploymentProcessorTarget processorTarget) {
            processorTarget.addDeploymentProcessor(SwitchYardExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, _priority++, new SwitchYardModuleDependencyProcessor(moduleId));
        }
    }, OperationContext.Stage.RUNTIME);

    final SwitchYardComponentService componentService = new SwitchYardComponentService(moduleId, model);
    final ServiceBuilder<Component> componentServiceBuilder = context.getServiceTarget().addService(SwitchYardComponentService.SERVICE_NAME.append(moduleId), componentService);
    componentServiceBuilder.addDependency(SwitchYardInjectorService.SERVICE_NAME, Map.class, componentService.getInjectedValues())
            .addDependency(RA_REPOSITORY_SERVICE_NAME, ResourceAdapterRepository.class, componentService.getResourceAdapterRepository());
    componentServiceBuilder.setInitialMode(Mode.ACTIVE);
    componentServiceBuilder.install();
}
 
Example 32
Project: wildfly-core   File: MBeanServerService.java   Source Code and License 6 votes vote down vote up
public static ServiceController<?> addService(final OperationContext context, final String resolvedDomainName, final String expressionsDomainName, final boolean legacyWithProperPropertyFormat,
                                              final boolean coreMBeanSensitivity,
                                              final ManagedAuditLogger auditLoggerInfo,
                                              final JmxAuthorizer authorizer,
                                              final Supplier<SecurityIdentity> securityIdentitySupplier,
                                              final JmxEffect jmxEffect,
                                              final ProcessType processType, final boolean isMasterHc) {
    final MBeanServerService service = new MBeanServerService(resolvedDomainName, expressionsDomainName, legacyWithProperPropertyFormat,
            coreMBeanSensitivity, auditLoggerInfo, authorizer, securityIdentitySupplier, jmxEffect, processType, isMasterHc);
    final ServiceName modelControllerName = processType.isHostController() ?
            DOMAIN_CONTROLLER_NAME : Services.JBOSS_SERVER_CONTROLLER;
    return context.getServiceTarget().addService(MBeanServerService.SERVICE_NAME, service)
        .setInitialMode(ServiceController.Mode.ACTIVE)
        .addDependency(modelControllerName, ModelController.class, service.modelControllerValue)
        .addDependency(context.getCapabilityServiceName("org.wildfly.management.notification-handler-registry", null), NotificationHandlerRegistry.class, service.notificationRegistryValue)
        .addDependency(ManagementModelIntegration.SERVICE_NAME, ManagementModelIntegration.ManagementModelProvider.class, service.managementModelProviderValue)
        .addAliases(LEGACY_MBEAN_SERVER_NAME)
            .install();
}
 
Example 33
Project: wildfly-core   File: ClassLoadingMXBeanAttributeHandler.java   Source Code and License 6 votes vote down vote up
@Override
protected void executeReadAttribute(OperationContext context, ModelNode operation) throws OperationFailedException {

    final String name = operation.require(ModelDescriptionConstants.NAME).asString();

    if (PlatformMBeanConstants.OBJECT_NAME.getName().equals(name)) {
        context.getResult().set(ManagementFactory.CLASS_LOADING_MXBEAN_NAME);
    } else if (PlatformMBeanConstants.TOTAL_LOADED_CLASS_COUNT.equals(name)) {
        context.getResult().set(ManagementFactory.getClassLoadingMXBean().getTotalLoadedClassCount());
    } else if (PlatformMBeanConstants.LOADED_CLASS_COUNT.equals(name)) {
        context.getResult().set(ManagementFactory.getClassLoadingMXBean().getLoadedClassCount());
    } else if (PlatformMBeanConstants.UNLOADED_CLASS_COUNT.equals(name)) {
        context.getResult().set(ManagementFactory.getClassLoadingMXBean().getUnloadedClassCount());
    } else if (PlatformMBeanConstants.VERBOSE.equals(name)) {
        context.getResult().set(ManagementFactory.getClassLoadingMXBean().isVerbose());
    } else if (CLASSLOADING_METRICS.contains(name)
            || CLASSLOADING_READ_WRITE_ATTRIBUTES.contains(name)) {
        // Bug
        throw PlatformMBeanLogger.ROOT_LOGGER.badReadAttributeImpl(name);
    } else {
        // Shouldn't happen; the global handler should reject
        throw unknownAttribute(operation);
    }

}
 
Example 34
Project: wildfly-core   File: ReadResourceDescriptionHandler.java   Source Code and License 6 votes vote down vote up
private List<PathAddress> getLocalResourceAddresses(OperationContext context, PathAddress opAddr){
    List<PathAddress> localResourceAddresses = null;
    if (parentAddresses == null) {
        if (opAddr.size() == 0) {
            return Collections.singletonList(PathAddress.EMPTY_ADDRESS);
        } else {
            localResourceAddresses = new ArrayList<>();
            getAllActualResourceAddresses(context, localResourceAddresses, PathAddress.EMPTY_ADDRESS, opAddr);
        }
    } else {
        localResourceAddresses = new ArrayList<>();
        for (PathAddress pathAddress : parentAddresses) {
            getAllActualResourceAddresses(context, localResourceAddresses, pathAddress, opAddr);
        }
    }
    return localResourceAddresses;

}
 
Example 35
Project: wildfly-core   File: AbstractDeploymentUploadHandler.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {

    if (contentRepository != null) {
        // Trigger authz
        AuthorizationResult authorizationResult = context.authorize(operation, ACTION_EFFECT_SET);
        authorizationResult.failIfDenied(operation, context.getCurrentAddress());

        try {
            InputStream is = getContentInputStream(context, operation);
            try {
                byte[] hash = contentRepository.addContent(is);
                context.getResult().set(hash);
            }
            finally {
                safeClose(is);
            }
        }
        catch (IOException e) {
            throw ROOT_LOGGER.caughtIOExceptionUploadingContent(e);
        }
    }
    // else this is a slave domain controller and we should ignore this operation
}
 
Example 36
Project: wildfly-core   File: RealmMapperDefinitions.java   Source Code and License 6 votes vote down vote up
static ResourceDefinition getConstantRealmMapper() {
    AbstractAddStepHandler add = new TrivialAddHandler<RealmMapper>(RealmMapper.class, CONSTANT_REALM_MAPPER_ATTRIBUTES, REALM_MAPPER_RUNTIME_CAPABILITY) {

        @Override
        protected ValueSupplier<RealmMapper> getValueSupplier(ServiceBuilder<RealmMapper> serviceBuilder,
                OperationContext context, ModelNode model) throws OperationFailedException {
            final String realmName = REALM_NAME.resolveModelAttribute(context, model).asString();

            return () -> RealmMapper.single(realmName);
        }
    };

    return TrivialResourceDefinition.builder()
            .setPathKey(ElytronDescriptionConstants.CONSTANT_REALM_MAPPER)
            .setAddHandler(add)
            .setAttributes(CONSTANT_REALM_MAPPER_ATTRIBUTES)
            .setRuntimeCapabilities(REALM_MAPPER_RUNTIME_CAPABILITY).build();
}
 
Example 37
Project: wildfly-core   File: ModifiableRealmDecorator.java   Source Code and License 6 votes vote down vote up
/**
 * Try to obtain a {@link ModifiableRealmIdentity} based on the identity and {@link ModifiableSecurityRealm} associated with given {@link OperationContext}.
 *
 * @param context the current context
 * @return the current identity
 * @throws OperationFailedException if the identity does not exists or if any error occurs while obtaining it.
 */
static ModifiableRealmIdentity getRealmIdentity(OperationContext context, String principalName) throws OperationFailedException {
    ModifiableSecurityRealm modifiableRealm = getModifiableSecurityRealm(context);
    ModifiableRealmIdentity realmIdentity = null;
    try {
        realmIdentity = modifiableRealm.getRealmIdentityForUpdate(new NamePrincipal(principalName));

        if (!realmIdentity.exists()) {
            throw new OperationFailedException(ROOT_LOGGER.identityNotFound(principalName));
        }

        return realmIdentity;
    } catch (RealmUnavailableException e) {
        throw ROOT_LOGGER.couldNotReadIdentity(principalName, e);
    } finally {
        if (realmIdentity != null) {
            realmIdentity.dispose();
        }
    }
}
 
Example 38
Project: wildfly-core   File: SyncServerStateOperationHandler.java   Source Code and License 6 votes vote down vote up
private boolean checkOperationForRestartRequired(final OperationContext context, final ModelNode operation) {
    boolean restart = false;
    final ImmutableManagementResourceRegistration registration = context.getResourceRegistration();
    final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    // an example of this is toggling jts:
    // /profile=full/subsystem=transactions:write-attribute(name=jts, value=true)
    // previously on a reconnect to the DC the slave check would flag reload-required on a WRITE_ATTRIBUTE / UNDEFINE_ATTRIBUTE,
    // so would get flagged into reload-required, but it really should be restart-required to match what would happen doing it with the DC
    // online, and the registration of the jts attribute.
    final String opName = operation.get(OP).asString();
    if (WRITE_ATTRIBUTE_OPERATION.equals(opName) || UNDEFINE_ATTRIBUTE_OPERATION.equals(opName)) {
        // look up the attribute name we're writing, and check the flags to see if we need restart.
        final String attributeName = operation.get(NAME).asString();
        // look up if the attribute requires restart / reload
        if (registration.getAttributeAccess(address, attributeName).getFlags().contains(AttributeAccess.Flag.RESTART_JVM)) {
            restart = true;
        }
    } else { // all other ops
        final Set<OperationEntry.Flag> flags = registration.getOperationFlags(address, opName);
        if (flags.contains(OperationEntry.Flag.RESTART_JVM)) {
            restart = true;
        }
    }
    return restart;
}
 
Example 39
Project: wildfly-core   File: CredentialStoreResourceDefinition.java   Source Code and License 6 votes vote down vote up
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    ServiceName credentialStoreServiceName = CREDENTIAL_STORE_UTIL.serviceName(operation);
    ServiceController<?> credentialStoreServiceController = context.getServiceRegistry(writeAccess).getRequiredService(credentialStoreServiceName);
    State serviceState;
    if ((serviceState = credentialStoreServiceController.getState()) != State.UP) {
        if (serviceMustBeUp) {
            try {
                // give it another chance to wait at most 500 mill-seconds
                credentialStoreServiceController.awaitValue(500, TimeUnit.MILLISECONDS);
            } catch (InterruptedException | IllegalStateException | TimeoutException e) {
                throw ROOT_LOGGER.requiredServiceNotUp(credentialStoreServiceName, credentialStoreServiceController.getState());
            }
        }
        serviceState = credentialStoreServiceController.getState();
        if (serviceState != State.UP) {
            if (serviceMustBeUp) {
                throw ROOT_LOGGER.requiredServiceNotUp(credentialStoreServiceName, serviceState);
            }
            return;
        }
    }
    CredentialStoreService service = (CredentialStoreService) credentialStoreServiceController.getService();
    performRuntime(context.getResult(), context, operation, service);
}
 
Example 40
Project: wildfly-core   File: ReadOperationDescriptionHandler.java   Source Code and License 6 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {

    String operationName = NAME.resolveModelAttribute(context, operation).asString();
    boolean accessControl = ACCESS_CONTROL.resolveModelAttribute(context, operation).asBoolean();

    final DescribedOp describedOp = getDescribedOp(context, operationName, operation, !accessControl);
    if (describedOp == null || (context.getProcessType() == ProcessType.DOMAIN_SERVER &&
            !(describedOp.flags.contains(OperationEntry.Flag.RUNTIME_ONLY) || describedOp.flags.contains(OperationEntry.Flag.READ_ONLY)))) {
        throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.operationNotRegistered(operationName, context.getCurrentAddress()));
    } else {
        ModelNode result = describedOp.getDescription();

        if (accessControl) {
            final PathAddress address = context.getCurrentAddress();
            ModelNode operationToCheck = Util.createOperation(operationName, address);
            operationToCheck.get(OPERATION_HEADERS).set(operation.get(OPERATION_HEADERS));
            AuthorizationResult authorizationResult = context.authorizeOperation(operationToCheck);
            result.get(ACCESS_CONTROL.getName(), EXECUTE).set(authorizationResult.getDecision() == Decision.PERMIT);

        }

        context.getResult().set(result);
    }
}