Example #1
0
    @Override
    public OperationResult execute(
        OperationContext context, ModelNode operation, ResultHandler resultHandler) {
      final ModelNode model = context.getSubModel();

      PathAddress rootAddress =
          PathAddress.pathAddress(
              PathAddress.pathAddress(operation.require(OP_ADDR)).getLastElement());
      final ModelNode result = new ModelNode();

      final ModelNode subsystem = new ModelNode();
      subsystem.get(OP).set(ADD);
      subsystem.get(OP_ADDR).set(rootAddress.toModelNode());
      if (model.has(ACTIVATION)) {
        subsystem.get(ACTIVATION).set(model.get(ACTIVATION));
      }
      if (model.has(CONFIGURATION)) {
        subsystem.get(CONFIGURATION).set(model.get(CONFIGURATION));
      }
      if (model.has(PROPERTIES)) {
        subsystem.get(PROPERTIES).set(model.get(PROPERTIES));
      }
      if (model.has(MODULES)) {
        subsystem.get(MODULES).set(model.get(MODULES));
      }
      result.add(subsystem);

      resultHandler.handleResultFragment(Util.NO_LOCATION, result);
      resultHandler.handleResultComplete();
      return new BasicOperationResult();
    }
    @Override
    public Cancellable execute(
        final OperationContext context,
        final ModelNode operation,
        final ResultHandler resultHandler) {
      final ModelNode model = context.getSubModel();

      final ModelNode subsystem = new ModelNode();
      subsystem.get(OP).set(ADD);
      subsystem.get(OP_ADDR).add(SUBSYSTEM, SUBSYSTEM_NAME);

      if (model.hasDefined(AUTHENTICATION_MANAGER_CLASS_NAME)) {
        subsystem
            .get(AUTHENTICATION_MANAGER_CLASS_NAME)
            .set(model.get(AUTHENTICATION_MANAGER_CLASS_NAME));
      }
      if (subsystem.hasDefined(DEEP_COPY_SUBJECT_MODE)) {
        subsystem.get(DEEP_COPY_SUBJECT_MODE).set(model.get(DEEP_COPY_SUBJECT_MODE));
      }
      if (subsystem.hasDefined(DEFAULT_CALLBACK_HANDLER_CLASS_NAME)) {
        subsystem
            .get(DEFAULT_CALLBACK_HANDLER_CLASS_NAME)
            .set(model.get(DEFAULT_CALLBACK_HANDLER_CLASS_NAME));
      }

      ModelNode result = new ModelNode();
      result.add(subsystem);

      resultHandler.handleResultFragment(Util.NO_LOCATION, result);
      resultHandler.handleResultComplete(null);
      return Cancellable.NULL;
    }
    @Override
    public Cancellable execute(
        OperationContext context, ModelNode operation, ResultHandler resultHandler) {
      ModelNode node = new ModelNode();
      node.add(createAddOperation());

      resultHandler.handleResultFragment(Util.NO_LOCATION, node);
      resultHandler.handleResultComplete(new ModelNode());
      return Cancellable.NULL;
    }
  @Override
  public OperationResult execute(
      OperationContext context, ModelNode operation, ResultHandler resultHandler)
      throws OperationFailedException {

    boolean master =
        context
            .getSubModel()
            .get(ModelDescriptionConstants.DOMAIN_CONTROLLER)
            .hasDefined(ModelDescriptionConstants.LOCAL);
    resultHandler.handleResultFragment(ResultHandler.EMPTY_LOCATION, new ModelNode().set(master));
    resultHandler.handleResultComplete();
    return new BasicOperationResult();
  }
Example #5
0
  /** {@inheritDoc} */
  @Override
  public OperationResult execute(
      OperationContext context, ModelNode operation, ResultHandler resultHandler) {

    if (context instanceof BootOperationContext) {

      /* set Hibernate persistence provider as the default provider */
      javax.persistence.spi.PersistenceProviderResolverHolder.setPersistenceProviderResolver(
          new PersistenceProviderResolverImpl());

      PersistenceProviderAdapterRegistry.putPersistenceProviderAdaptor(
          "org.hibernate.ejb.HibernatePersistence", new HibernatePersistenceProviderAdaptor());

      final BootOperationContext updateContext = (BootOperationContext) context;
      updateContext.addDeploymentProcessor(
          Phase.PARSE, Phase.PARSE_PERSISTENCE_UNIT, new PersistenceUnitParseProcessor());
      updateContext.addDeploymentProcessor(
          Phase.PARSE, Phase.PARSE_PERSISTENCE_ANNOTATION, new JPAAnnotationParseProcessor());
      updateContext.addDeploymentProcessor(
          Phase.DEPENDENCIES, Phase.DEPENDENCIES_JPA, new JPADependencyProcessor());
      updateContext.addDeploymentProcessor(
          Phase.INSTALL, Phase.INSTALL_PERSISTENCE_REF, new PersistenceRefProcessor());
      updateContext.addDeploymentProcessor(
          Phase.INSTALL, Phase.INSTALL_PERSISTENTUNIT, new PersistenceUnitDeploymentProcessor());
    }

    final ModelNode compensatingOperation = new ModelNode();
    compensatingOperation.get(OP).set(REMOVE);
    compensatingOperation.get(OP_ADDR).set(operation.require(OP_ADDR));

    context.getSubModel().setEmptyObject();
    resultHandler.handleResultComplete();
    return new BasicOperationResult(compensatingOperation);
  }
  /** {@inheritDoc} */
  @Override
  public Cancellable execute(
      final OperationContext context, ModelNode operation, ResultHandler resultHandler) {

    String threadPoolName = operation.require(THREAD_POOL).asString();
    context.getSubModel().get(THREAD_POOL).set(threadPoolName);
    // initialize the connectors
    context.getSubModel().get(CONNECTOR).setEmptyObject();

    // Compensating is remove
    final ModelNode compensating = Util.getResourceRemoveOperation(operation.require(OP_ADDR));

    if (context instanceof RuntimeOperationContext) {
      final RuntimeOperationContext updateContext = (RuntimeOperationContext) context;
      // create endpoint
      final EndpointService endpointService = new EndpointService();
      // todo configure option map
      endpointService.setOptionMap(OptionMap.EMPTY);
      final Injector<Executor> executorInjector = endpointService.getExecutorInjector();

      updateContext
          .getServiceTarget()
          .addService(RemotingServices.ENDPOINT, endpointService)
          .addDependency(
              ThreadsServices.executorName(threadPoolName),
              new CastingInjector<Executor>(executorInjector, Executor.class))
          .setInitialMode(ServiceController.Mode.ACTIVE)
          .install();
    }

    resultHandler.handleResultComplete(compensating);

    return Cancellable.NULL;
  }
  /** {@inheritDoc} */
  @Override
  public OperationResult execute(
      OperationContext context, ModelNode operation, ResultHandler resultHandler)
      throws OperationFailedException {

    validator.validate(operation);

    String name = operation.require(NAME).asString();
    String toReplace = operation.require(TO_REPLACE).asString();

    if (name.equals(toReplace)) {
      throw operationFailed(
          String.format(
              "Cannot use %s with the same value for parameters %s and %s. "
                  + "Use %s to redeploy the same content or %s to replace content with a new version with the same name.",
              OPERATION_NAME,
              NAME,
              TO_REPLACE,
              ServerGroupDeploymentRedeployHandler.OPERATION_NAME,
              DeploymentFullReplaceHandler.OPERATION_NAME));
    }

    ModelNode deployment;
    try {
      deployment =
          context.getSubModel(PathAddress.pathAddress(PathElement.pathElement(DEPLOYMENT, name)));
    } catch (IllegalArgumentException iae) {
      throw operationFailed(String.format("No deployment with name %s found", name));
    }

    byte[] hash = deployment.require(HASH).asBytes();
    // Ensure the local repo has the files
    fileRepository.getDeploymentFiles(hash);

    ModelNode deployments = context.getSubModel().get(DEPLOYMENT);
    ModelNode deployNode = deployments.hasDefined(name) ? deployments.get(name) : null;
    ModelNode replaceNode = deployments.hasDefined(toReplace) ? deployments.get(toReplace) : null;
    if (deployNode == null) {
      deployNode = deployment.clone();
      deployments.get(name).set(deployNode);
    } else if (deployNode.get(START).asBoolean()) {
      throw operationFailed(String.format("Deployment %s is already started", toReplace));
    } else if (replaceNode == null) {
      throw operationFailed(String.format("No deployment with name %s found", toReplace));
    }

    // Update model
    deployNode.get(START).set(true);
    replaceNode.get(START).set(false);

    ModelNode compensatingOp = operation.clone();
    compensatingOp.get(NAME).set(toReplace);
    compensatingOp.get(TO_REPLACE).set(name);

    resultHandler.handleResultComplete();

    return new BasicOperationResult();
  }
    /** {@inheritDoc} */
    @Override
    public OperationResult execute(
        final OperationContext context,
        final ModelNode operation,
        final ResultHandler resultHandler)
        throws OperationFailedException {

      final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
      final String jndiName = address.getLastElement().getValue();
      final String parameterName = operation.require(NAME).asString();

      final ModelNode submodel = context.getSubModel();
      final ModelNode currentValue = submodel.get(parameterName).clone();

      resultHandler.handleResultFragment(new String[0], currentValue);
      resultHandler.handleResultComplete();

      return new BasicOperationResult();
    }
Example #9
0
    @Override
    public OperationResult execute(
        final OperationContext context,
        final ModelNode operation,
        final ResultHandler resultHandler) {
      ModelNode result = new ModelNode();

      result.add(
          Util.getEmptyOperation(
              ADD, pathAddress(PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME))));

      final ModelNode model = context.getSubModel();
      addBoundedQueueThreadPools(result, model);
      addQueuelessThreadPools(result, model);
      addScheduledThreadPools(result, model);
      addThreadFactories(result, model);
      addUnboundedQueueThreadPools(result, model);

      resultHandler.handleResultFragment(Util.NO_LOCATION, result);
      resultHandler.handleResultComplete();
      return new BasicOperationResult();
    }
  /** {@inheritDoc} */
  @Override
  public OperationResult execute(
      final OperationContext context,
      final ModelNode operation,
      final ResultHandler resultHandler) {

    final ModelNode result = new ModelNode();
    final PathAddress rootAddress =
        PathAddress.pathAddress(
            PathAddress.pathAddress(operation.require(OP_ADDR)).getLastElement());
    final ModelNode subModel = context.getSubModel();

    final ModelNode subsystemAdd = new ModelNode();
    subsystemAdd.get(OP).set(ADD);
    subsystemAdd.get(OP_ADDR).set(rootAddress.toModelNode());

    if (subModel.hasDefined(MODIFY_WSDL_ADDRESS)) {
      subsystemAdd.get(MODIFY_WSDL_ADDRESS).set(subModel.get(MODIFY_WSDL_ADDRESS));
    }

    if (subModel.hasDefined(WSDL_HOST)) {
      subsystemAdd.get(WSDL_HOST).set(subModel.get(WSDL_HOST));
    }

    if (subModel.hasDefined(WSDL_PORT)) {
      subsystemAdd.get(WSDL_PORT).set(subModel.get(WSDL_PORT));
    }

    if (subModel.hasDefined(WSDL_SECURE_PORT)) {
      subsystemAdd.get(WSDL_SECURE_PORT).set(subModel.get(WSDL_SECURE_PORT));
    }

    result.add(subsystemAdd);

    resultHandler.handleResultFragment(Util.NO_LOCATION, result);
    resultHandler.handleResultComplete();
    return new BasicOperationResult();
  }
  /** {@inheritDoc} */
  @Override
  public Cancellable execute(
      OperationContext context, ModelNode operation, ResultHandler resultHandler) {

    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    final String name = address.getLastElement().getValue();

    final ModelNode compensatingOperation = new ModelNode();
    compensatingOperation.get(OP).set("enable");
    compensatingOperation.get(OP_ADDR).set(operation.require(OP_ADDR));

    // update the model
    context.getSubModel().get(CommonAttributes.SCAN_ENABLED).set(false);

    if (context instanceof RuntimeOperationContext) {
      final RuntimeOperationContext updateContext = (RuntimeOperationContext) context;
      final ServiceController<?> controller =
          updateContext
              .getServiceRegistry()
              .getService(DeploymentScannerService.getServiceName(name));
      if (controller == null) {
        resultHandler.handleFailed(new ModelNode().set("scanner not configured"));
      } else {
        try {
          final DeploymentScanner scanner = (DeploymentScanner) controller.getValue();
          scanner.stopScanner();
          resultHandler.handleResultComplete(compensatingOperation);
        } catch (Throwable t) {
          resultHandler.handleFailed(getFailureResult(t));
        }
      }
    } else {
      resultHandler.handleResultComplete(compensatingOperation);
    }

    return Cancellable.NULL;
  }
  public OperationResult execute(
      final OperationContext context, final ModelNode operation, final ResultHandler resultHandler)
      throws OperationFailedException {
    final ModelNode opAddr = operation.require(OP_ADDR);

    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    final String name = address.getLastElement().getValue();

    final ModelNode model = context.getSubModel();

    final ModelNode compensatingOperation = new ModelNode();
    compensatingOperation.get(OP).set(OPERATION_NAME);
    compensatingOperation.get(OP_ADDR).set(opAddr);

    if (operation.hasDefined(LEVEL)) {
      apply(model, compensatingOperation, LEVEL);
      apply(operation, model, LEVEL);
    }
    if (operation.hasDefined(FORMATTER)) {
      apply(model, compensatingOperation, FORMATTER);
      apply(operation, model, FORMATTER);
    }
    if (operation.hasDefined(ENCODING)) {
      apply(model, compensatingOperation, ENCODING);
      apply(operation, model, ENCODING);
    }

    updateModel(operation, compensatingOperation, model);

    if (context.getRuntimeContext() != null) {
      context
          .getRuntimeContext()
          .setRuntimeTask(
              new RuntimeTask() {
                public void execute(RuntimeTaskContext context) throws OperationFailedException {
                  final ServiceRegistry serviceRegistry = context.getServiceRegistry();
                  final ServiceController<Handler> controller =
                      (ServiceController<Handler>)
                          serviceRegistry.getService(LogServices.handlerName(name));
                  if (controller != null) {
                    final Handler handler = controller.getValue();
                    if (operation.hasDefined(LEVEL)) {
                      handler.setLevel(Level.parse(operation.get(LEVEL).asString()));
                    }
                    if (operation.hasDefined(FORMATTER)) {
                      new PatternFormatterSpec(operation.get(FORMATTER).asString()).apply(handler);
                    }
                    if (operation.hasDefined(ENCODING)) {
                      try {
                        handler.setEncoding(operation.get(ENCODING).asString());
                      } catch (UnsupportedEncodingException e) {
                        throw new OperationFailedException(
                            e, new ModelNode().set("Failed to set handler encoding."));
                      }
                    }
                    updateRuntime(operation, handler);
                  }
                  resultHandler.handleResultComplete();
                }
              });
    } else {
      resultHandler.handleResultComplete();
    }

    return new BasicOperationResult(compensatingOperation);
  }
  public OperationResult execute(
      final OperationContext context, final ModelNode operation, final ResultHandler resultHandler)
      throws OperationFailedException {
    final ModelNode opAddr = operation.require(OP_ADDR);
    final String jndiName = PathAddress.pathAddress(opAddr).getLastElement().getValue();

    // Compensating is add
    final ModelNode model = context.getSubModel();
    final ModelNode compensating = Util.getEmptyOperation(ADD, opAddr);

    if (model.has(CONNECTION_PROPERTIES)) {
      for (ModelNode property : model.get(CONNECTION_PROPERTIES).asList()) {
        compensating
            .get(CONNECTION_PROPERTIES, property.asProperty().getName())
            .set(property.asString());
      }
    }
    for (final AttributeDefinition attribute : getModelProperties()) {
      if (model.get(attribute.getName()).isDefined()) {
        compensating.get(attribute.getName()).set(model.get(attribute.getName()));
      }
    }

    if (context.getRuntimeContext() != null) {
      context
          .getRuntimeContext()
          .setRuntimeTask(
              new RuntimeTask() {
                public void execute(RuntimeTaskContext context) throws OperationFailedException {
                  final ServiceRegistry registry = context.getServiceRegistry();

                  final ServiceName binderServiceName =
                      ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(jndiName);
                  final ServiceController<?> binderController =
                      registry.getService(binderServiceName);
                  if (binderController != null) {
                    binderController.setMode(ServiceController.Mode.REMOVE);
                  }

                  final ServiceName referenceFactoryServiceName =
                      DataSourceReferenceFactoryService.SERVICE_NAME_BASE.append(jndiName);
                  final ServiceController<?> referenceFactoryController =
                      registry.getService(referenceFactoryServiceName);
                  if (referenceFactoryController != null) {
                    referenceFactoryController.setMode(ServiceController.Mode.REMOVE);
                  }

                  final ServiceName dataSourceServiceName =
                      AbstractDataSourceService.SERVICE_NAME_BASE.append(jndiName);
                  final ServiceController<?> dataSourceController =
                      registry.getService(dataSourceServiceName);
                  if (dataSourceController != null) {
                    dataSourceController.setMode(ServiceController.Mode.REMOVE);
                  }
                  resultHandler.handleResultComplete();
                }
              });
    } else {
      resultHandler.handleResultComplete();
    }

    return new BasicOperationResult(compensating);
  }
    @Override
    protected boolean applyUpdateToRuntime(
        final OperationContext context,
        final ModelNode operation,
        final ResultHandler resultHandler,
        final String parameterName,
        final ModelNode newValue,
        final ModelNode currentValue)
        throws OperationFailedException {
      if (context.getRuntimeContext() != null) {
        context
            .getRuntimeContext()
            .setRuntimeTask(
                new RuntimeTask() {
                  public void execute(RuntimeTaskContext runtimeCtx)
                      throws OperationFailedException {
                    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
                    final String jndiName = address.getLastElement().getValue();

                    final ServiceController<?> managementRepoService =
                        runtimeCtx
                            .getServiceRegistry()
                            .getService(ConnectorServices.MANAGEMENT_REPOSISTORY_SERVICE);
                    if (managementRepoService != null) {
                      try {
                        final ManagementRepository repository =
                            (ManagementRepository) managementRepoService.getValue();
                        List<PoolConfiguration> poolConfigs =
                            getMatchingPoolConfigs(jndiName, repository);
                        for (PoolConfiguration pc : poolConfigs) {
                          if (MAX_POOL_SIZE.equals(parameterName)) {
                            pc.setMaxSize(newValue.asInt());
                          }
                          if (MIN_POOL_SIZE.equals(parameterName)) {
                            pc.setMinSize(newValue.asInt());
                          }
                          if (BLOCKING_TIMEOUT_WAIT_MILLIS.equals(parameterName)) {
                            pc.setBlockingTimeout(newValue.asLong());
                          }
                          if (POOL_USE_STRICT_MIN.equals(parameterName)) {
                            pc.setStrictMin(newValue.asBoolean());
                          }
                          if (USE_FAST_FAIL.equals(parameterName)) {
                            pc.setUseFastFail(newValue.asBoolean());
                          }
                        }

                        resultHandler.handleResultComplete();

                      } catch (Exception e) {
                        throw new OperationFailedException(
                            new ModelNode().set("failed to set attribute" + e.getMessage()));
                      }
                    } else {
                      resultHandler.handleResultComplete();
                    }
                  }
                });
      } else {
        resultHandler.handleResultComplete();
      }
      return (IDLETIMEOUTMINUTES.equals(parameterName)
          || BACKGROUNDVALIDATION.equals(parameterName)
          || BACKGROUNDVALIDATIONMINUTES.equals(parameterName)
          || POOL_PREFILL.equals(parameterName));
    }
Example #15
0
  /** {@inheritDoc} */
  @Override
  public OperationResult execute(
      final OperationContext context,
      final ModelNode operation,
      final ResultHandler resultHandler) {

    final ModelNode compensatingOperation =
        Util.getResourceRemoveOperation(operation.require(OP_ADDR));

    if (context instanceof BootOperationContext) {
      final BootOperationContext updateContext = (BootOperationContext) context;

      context
          .getRuntimeContext()
          .setRuntimeTask(
              new RuntimeTask() {
                @Override
                public void execute(RuntimeTaskContext context) throws OperationFailedException {
                  final ServiceTarget serviceTarget = context.getServiceTarget();
                  final EJBUtilities utilities = new EJBUtilities();
                  serviceTarget
                      .addService(EJBUtilities.SERVICE_NAME, utilities)
                      .addDependency(
                          TxnServices.JBOSS_TXN_TRANSACTION_MANAGER,
                          TransactionManager.class,
                          utilities.getTransactionManagerInjector())
                      .addDependency(
                          TxnServices.JBOSS_TXN_SYNCHRONIZATION_REGISTRY,
                          TransactionSynchronizationRegistry.class,
                          utilities.getTransactionSynchronizationRegistryInjector())
                      .addDependency(
                          TxnServices.JBOSS_TXN_USER_TRANSACTION,
                          UserTransaction.class,
                          utilities.getUserTransactionInjector())
                      .setInitialMode(ServiceController.Mode.ACTIVE)
                      .install();
                  resultHandler.handleResultComplete(); // TODO: Listener
                }
              });

      // add the metadata parser deployment processor
      updateContext.addDeploymentProcessor(
          Phase.PARSE, Phase.PARSE_EJB_DEPLOYMENT, new EjbJarParsingDeploymentUnitProcessor());
      updateContext.addDeploymentProcessor(
          Phase.PARSE, Phase.PARSE_EJB_ANNOTATION, new EjbAnnotationProcessor());
      updateContext.addDeploymentProcessor(
          Phase.PARSE,
          Phase.PARSE_MESSAGE_DRIVEN_ANNOTATION,
          new MessageDrivenAnnotationProcessor());
      // Process @DependsOn after the @Singletons have been registered.
      updateContext.addDeploymentProcessor(
          Phase.PARSE, Phase.PARSE_EJB_ANNOTATION, new EjbDependsOnAnnotationProcessor());
      updateContext.addDeploymentProcessor(
          Phase.PARSE, Phase.PARSE_EJB_CONTEXT_BINDING, new EjbContextJndiBindingProcessor());
      updateContext.addDeploymentProcessor(
          Phase.PARSE,
          Phase.PARSE_EJB_TRANSACTION_MANAGEMENT,
          new TransactionManagementAnnotationProcessor());
      updateContext.addDeploymentProcessor(
          Phase.PARSE,
          Phase.PARSE_EJB_LOCAL_VIEW_ANNOTATION,
          new LocalEjbViewAnnotationProcessor());
      updateContext.addDeploymentProcessor(
          Phase.PARSE,
          Phase.PARSE_EJB_NO_INTERFACE_VIEW_ANNOTATION,
          new NoInterfaceViewAnnotationProcessor());
      updateContext.addDeploymentProcessor(
          Phase.PARSE,
          Phase.PARSE_EJB_INJECTION_ANNOTATION,
          new EjbResourceInjectionAnnotationProcessor());
      updateContext.addDeploymentProcessor(
          Phase.PARSE, Phase.PARSE_EJB_STARTUP_ANNOTATION, new StartupAnnotationProcessor());
      updateContext.addDeploymentProcessor(
          Phase.PARSE,
          Phase.PARSE_EJB_CONCURRENCY_MANAGEMENT_ANNOTATION,
          new ConcurrencyManagementAnnotationProcessor());
      updateContext.addDeploymentProcessor(
          Phase.PARSE, Phase.PARSE_EJB_LOCK_ANNOTATION, new LockAnnotationProcessor());
      updateContext.addDeploymentProcessor(
          Phase.PARSE,
          Phase.PARSE_EJB_ACCESS_TIMEOUT_ANNOTATION,
          new AccessTimeoutAnnotationProcessor());
      updateContext.addDeploymentProcessor(
          Phase.PARSE,
          Phase.PARSE_EJB_TRANSACTION_ATTR_ANNOTATION,
          new TransactionAttributeAnnotationProcessor());
      updateContext.addDeploymentProcessor(
          Phase.PARSE,
          Phase.PARSE_EJB_RESOURCE_ADAPTER_ANNOTATION,
          new ResourceAdapterAnnotationProcessor());

      updateContext.addDeploymentProcessor(
          Phase.DEPENDENCIES, Phase.DEPENDENCIES_EJB, new EjbDependencyDeploymentUnitProcessor());

      updateContext.addDeploymentProcessor(
          Phase.POST_MODULE,
          Phase.POST_MODULE_EJB_JNDI_BINDINGS,
          new EjbJndiBindingsDeploymentUnitProcessor());

      // add the real deployment processor
      // TODO: add the proper deployment processors
      // updateContext.addDeploymentProcessor(processor, priority);
    }

    context.getSubModel().setEmptyObject();
    resultHandler.handleResultComplete();
    return new BasicOperationResult(compensatingOperation);
  }
  /** {@inheritDoc} */
  @Override
  public OperationResult execute(
      OperationContext context, ModelNode operation, ResultHandler resultHandler)
      throws OperationFailedException {

    validator.validate(operation);

    String name = operation.require(NAME).asString();
    String runtimeName =
        operation.hasDefined(RUNTIME_NAME) ? operation.get(RUNTIME_NAME).asString() : name;
    byte[] hash;
    if (operation.hasDefined(INPUT_STREAM_INDEX) && operation.hasDefined(HASH)) {
      throw new OperationFailedException(
          new ModelNode().set("Can't pass in both an input-stream-index and a hash"));
    } else if (operation.hasDefined(INPUT_STREAM_INDEX)) {
      InputStream in = getContents(context, operation);
      try {
        hash = deploymentRepository.addDeploymentContent(in);
      } catch (IOException e) {
        throw new OperationFailedException(new ModelNode().set(e.toString()));
      }
    } else if (operation.hasDefined(HASH)) {

      hash = operation.get(HASH).asBytes();
      if (!deploymentRepository.hasDeploymentContent(hash)) {
        throw new OperationFailedException(
            new ModelNode()
                .set(
                    String.format(
                        "No deployment content with hash %s is available in the deployment content repository.",
                        HashUtil.bytesToHexString(hash))));
      }
    } else {
      throw new OperationFailedException(
          new ModelNode().set("Neither an attachment or a hash were passed in"));
    }

    ModelNode rootModel = context.getSubModel();
    ModelNode deployments = rootModel.get(DEPLOYMENT);

    ModelNode replaceNode = deployments.hasDefined(name) ? deployments.get(name) : null;
    if (replaceNode == null) {
      throw new OperationFailedException(
          new ModelNode().set(String.format("No deployment with name %s found", name)));
    }

    boolean start = replaceNode.get(ENABLED).asBoolean();

    ModelNode deployNode = new ModelNode();
    deployNode.get(NAME).set(name);
    deployNode.get(RUNTIME_NAME).set(runtimeName);
    deployNode.get(HASH).set(hash);
    deployNode.get(ENABLED).set(start);

    deployments.get(name).set(deployNode);

    ModelNode compensatingOp = operation.clone();
    compensatingOp.get(RUNTIME_NAME).set(replaceNode.get(RUNTIME_NAME).asString());
    compensatingOp.get(HASH).set(replaceNode.get(HASH).asBytes());
    if (operation.hasDefined(INPUT_STREAM_INDEX)) {
      operation.remove(INPUT_STREAM_INDEX);
    }

    if (start) {
      DeploymentHandlerUtil.replace(deployNode, name, context, resultHandler);
    } else {
      resultHandler.handleResultComplete();
    }

    return new BasicOperationResult(compensatingOp);
  }
Example #17
0
  @Override
  public OperationResult execute(
      final OperationContext context, final ModelNode operation, final ResultHandler resultHandler)
      throws OperationFailedException {
    final ModelNode address = operation.require(OP_ADDR);
    final PathAddress pathAddress = PathAddress.pathAddress(address);

    final String moduleName = operation.require(DRIVER).asString();

    // Apply to the model
    final ModelNode model = context.getSubModel();
    model.get(NAME).set(pathAddress.getLastElement().getValue());
    model.get(DRIVER).set(moduleName);

    // Compensating is remove
    final ModelNode compensating = Util.getResourceRemoveOperation(address);

    if (context.getRuntimeContext() != null) {
      context
          .getRuntimeContext()
          .setRuntimeTask(
              new RuntimeTask() {
                @Override
                public void execute(RuntimeTaskContext context) throws OperationFailedException {
                  final ServiceTarget target = context.getServiceTarget();

                  final ModuleIdentifier moduleId;
                  final Module module;
                  try {
                    moduleId = ModuleIdentifier.create(moduleName);
                    module = Module.getCallerModuleLoader().loadModule(moduleId);
                  } catch (ModuleLoadException e) {
                    throw new OperationFailedException(
                        e,
                        new ModelNode()
                            .set("Failed to load module for driver [" + moduleName + "]"));
                  }
                  final ServiceLoader<Driver> serviceLoader = module.loadService(Driver.class);
                  if (serviceLoader != null)
                    for (Driver driver : serviceLoader) {

                      final int majorVersion = driver.getMajorVersion();
                      final int minorVersion = driver.getMinorVersion();
                      final boolean compliant = driver.jdbcCompliant();
                      if (compliant) {
                        log.infof(
                            "Deploying JDBC-compliant driver %s (version %d.%d)",
                            driver.getClass(),
                            Integer.valueOf(majorVersion),
                            Integer.valueOf(minorVersion));
                      } else {
                        log.infof(
                            "Deploying non-JDBC-compliant driver %s (version %d.%d)",
                            driver.getClass(),
                            Integer.valueOf(majorVersion),
                            Integer.valueOf(minorVersion));
                      }
                      InstalledDriver driverMetadata =
                          new InstalledDriver(
                              moduleId,
                              driver.getClass().getName(),
                              majorVersion,
                              minorVersion,
                              compliant);
                      DriverService driverService = new DriverService(driverMetadata, driver);
                      target
                          .addService(
                              ServiceName.JBOSS.append(
                                  "jdbc-driver",
                                  driver.getClass().getName(),
                                  Integer.toString(majorVersion),
                                  Integer.toString(minorVersion)),
                              driverService)
                          .addDependency(
                              ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE,
                              DriverRegistry.class,
                              driverService.getDriverRegistryServiceInjector())
                          .setInitialMode(ServiceController.Mode.ACTIVE)
                          .install();
                    }
                  resultHandler.handleResultComplete();
                }
              });
    } else {
      resultHandler.handleResultComplete();
    }
    return new BasicOperationResult(compensating);
  }
Example #18
0
  /** {@inheritDoc} */
  @Override
  public Cancellable execute(
      OperationContext context, ModelNode operation, ResultHandler resultHandler) {

    ModelNode opAddr = operation.require(OP_ADDR);
    final PathAddress address = PathAddress.pathAddress(opAddr);
    final String name = address.getLastElement().getValue();
    final String bindingRef = operation.require(SOCKET_BINDING).asString();

    final ModelNode compensatingOperation = Util.getResourceRemoveOperation(opAddr);

    final ModelNode subModel = context.getSubModel();
    subModel.get(PROTOCOL).set(operation.get(PROTOCOL));
    subModel.get(SOCKET_BINDING).set(operation.get(SOCKET_BINDING));
    if (operation.hasDefined(SCHEME)) subModel.get(SCHEME).set(operation.get(SCHEME));
    if (operation.hasDefined(SECURE)) subModel.get(SECURE).set(operation.get(SECURE).asBoolean());
    if (operation.hasDefined(ENABLED))
      subModel.get(ENABLED).set(operation.get(ENABLED).asBoolean());
    if (operation.hasDefined(ENABLE_LOOKUPS))
      subModel.get(ENABLE_LOOKUPS).set(operation.get(ENABLE_LOOKUPS).asBoolean());
    if (operation.hasDefined(EXECUTOR))
      subModel.get(EXECUTOR).set(operation.get(EXECUTOR).asString());
    if (operation.hasDefined(PROXY_NAME))
      subModel.get(PROXY_NAME).set(operation.get(PROXY_NAME).asString());
    if (operation.hasDefined(PROXY_PORT))
      subModel.get(PROXY_PORT).set(operation.get(PROXY_PORT).asInt());
    if (operation.hasDefined(REDIRECT_PORT))
      subModel.get(REDIRECT_PORT).set(operation.get(REDIRECT_PORT).asInt());
    if (operation.hasDefined(MAX_POST_SIZE))
      subModel.get(MAX_POST_SIZE).set(operation.get(MAX_POST_SIZE).asInt());
    if (operation.hasDefined(MAX_SAVE_POST_SIZE))
      subModel.get(MAX_SAVE_POST_SIZE).set(operation.get(MAX_SAVE_POST_SIZE).asInt());

    if (context instanceof RuntimeOperationContext) {
      final RuntimeOperationContext runtimeContext = (RuntimeOperationContext) context;

      final boolean enabled =
          operation.hasDefined(ENABLED) ? operation.get(ENABLED).asBoolean() : true;
      final WebConnectorService service =
          new WebConnectorService(
              operation.require(PROTOCOL).asString(), operation.get(SCHEME).asString());
      if (operation.hasDefined(SECURE)) service.setSecure(operation.get(SECURE).asBoolean());
      if (operation.hasDefined(ENABLE_LOOKUPS))
        service.setEnableLookups(operation.get(ENABLE_LOOKUPS).asBoolean());
      if (operation.hasDefined(PROXY_NAME))
        service.setProxyName(operation.get(PROXY_NAME).asString());
      if (operation.hasDefined(PROXY_PORT)) service.setProxyPort(operation.get(PROXY_PORT).asInt());
      if (operation.hasDefined(REDIRECT_PORT))
        service.setRedirectPort(operation.get(REDIRECT_PORT).asInt());
      if (operation.hasDefined(MAX_POST_SIZE))
        service.setMaxPostSize(operation.get(MAX_POST_SIZE).asInt());
      if (operation.hasDefined(MAX_SAVE_POST_SIZE))
        service.setMaxSavePostSize(operation.get(MAX_SAVE_POST_SIZE).asInt());
      runtimeContext
          .getServiceTarget()
          .addService(WebSubsystemServices.JBOSS_WEB_CONNECTOR.append(name), service)
          .addDependency(WebSubsystemServices.JBOSS_WEB, WebServer.class, service.getServer())
          .addDependency(
              SocketBinding.JBOSS_BINDING_NAME.append(bindingRef),
              SocketBinding.class,
              service.getBinding())
          .setInitialMode(enabled ? Mode.ACTIVE : Mode.NEVER)
          .install();
    }

    resultHandler.handleResultComplete(compensatingOperation);

    return Cancellable.NULL;
  }