Example #1
0
  @Override
  protected void recordCapabilitiesAndRequirements(
      OperationContext context, ModelNode operation, Resource resource)
      throws OperationFailedException {
    PathAddress address = context.getCurrentAddress();
    // The super implementation assumes that the capability name is a simple extension of the base
    // name - we do not.
    this.descriptor
        .getCapabilities()
        .forEach(capability -> context.deregisterCapability(capability.resolve(address).getName()));

    ModelNode model = resource.getModel();
    ImmutableManagementResourceRegistration registration = context.getResourceRegistration();
    registration
        .getAttributeNames(PathAddress.EMPTY_ADDRESS)
        .stream()
        .map(name -> registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, name))
        .filter(access -> access != null)
        .map(access -> access.getAttributeDefinition())
        .filter(
            attribute ->
                (attribute != null)
                    && (model.hasDefined(attribute.getName())
                        || attribute.hasCapabilityRequirements()))
        .forEach(
            attribute ->
                attribute.removeCapabilityRequirements(context, model.get(attribute.getName())));
  }
  protected void addRubyXaConnectionFactory(
      final OperationContext context,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> newControllers) {

    ServiceName managedFactoryServiceName =
        MessagingServices.RUBY_XA_CONNECTION_FACTORY.append("manager");

    ManagedReferenceInjectableService managementService = new ManagedReferenceInjectableService();
    newControllers.add(
        context
            .getServiceTarget()
            .addService(managedFactoryServiceName, managementService)
            .addDependency(
                getJMSConnectionFactoryServiceName(),
                ManagedReferenceFactory.class,
                managementService.getManagedReferenceFactoryInjector())
            .addListener(verificationHandler)
            .install());

    RubyXaConnectionFactoryService service = new RubyXaConnectionFactoryService();
    newControllers.add(
        context
            .getServiceTarget()
            .addService(MessagingServices.RUBY_XA_CONNECTION_FACTORY, service)
            .addDependency(
                managedFactoryServiceName,
                HornetQConnectionFactory.class,
                service.getConnectionFactoryInjector())
            .addListener(verificationHandler)
            .setInitialMode(Mode.ON_DEMAND)
            .install());
  }
Example #3
0
 static void reloadRequiredStep(final OperationContext context) {
   if (context.isNormalServer()) {
     context.addStep(
         new OperationStepHandler() {
           @Override
           public void execute(final OperationContext context, final ModelNode operation)
               throws OperationFailedException {
             final ServiceName hqServiceName =
                 MessagingServices.getHornetQServiceName(
                     PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
             final ServiceController<?> controller =
                 context.getServiceRegistry(false).getService(hqServiceName);
             OperationContext.RollbackHandler rh;
             if (controller != null) {
               context.reloadRequired();
               rh = OperationContext.RollbackHandler.REVERT_RELOAD_REQUIRED_ROLLBACK_HANDLER;
             } else {
               rh = OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER;
             }
             context.completeStep(rh);
           }
         },
         OperationContext.Stage.RUNTIME);
   }
 }
Example #4
0
  /**
   * [AS7-5850] Core queues created with ActiveMQ API does not create WildFly resources
   *
   * <p>For backwards compatibility if an operation is invoked on a queue that has no corresponding
   * resources, we forward the operation to the corresponding runtime-queue resource (which *does*
   * exist).
   *
   * @return true if the operation is forwarded to the corresponding runtime-queue resource, false
   *     else.
   */
  static boolean forwardToRuntimeQueue(
      OperationContext context, ModelNode operation, OperationStepHandler handler) {
    PathAddress address =
        PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));

    // do not forward if the current operation is for a runtime-queue already:
    if (RUNTIME_QUEUE.equals(address.getLastElement().getKey())) {
      return false;
    }

    String queueName = address.getLastElement().getValue();

    PathAddress activeMQPathAddress = MessagingServices.getActiveMQServerPathAddress(address);
    Resource serverResource = context.readResourceFromRoot(activeMQPathAddress);
    boolean hasChild = serverResource.hasChild(address.getLastElement());
    if (hasChild) {
      return false;
    } else {
      // there is no registered queue resource, forward to the runtime-queue address instead
      ModelNode forwardOperation = operation.clone();
      forwardOperation
          .get(ModelDescriptionConstants.OP_ADDR)
          .set(activeMQPathAddress.append(RUNTIME_QUEUE, queueName).toModelNode());
      context.addStep(forwardOperation, handler, OperationContext.Stage.RUNTIME, true);
      return true;
    }
  }
Example #5
0
 private static void addClusteringServices(
     final OperationContext context, final boolean appclient) {
   if (appclient) {
     return;
   }
   ServiceTarget target = context.getServiceTarget();
   target
       .addService(RegistryCollectorService.SERVICE_NAME, new RegistryCollectorService<>())
       .setInitialMode(ServiceController.Mode.ON_DEMAND)
       .install();
   target
       .addService(
           CacheFactoryBuilderRegistryService.SERVICE_NAME,
           new CacheFactoryBuilderRegistryService<>())
       .setInitialMode(ServiceController.Mode.ON_DEMAND)
       .install();
   if (context.hasOptionalCapability(
       SingletonPolicy.CAPABILITY_NAME.concat(".default"),
       CLUSTERED_SINGLETON_CAPABILITY.getName(),
       null)) {
     final ClusteredSingletonServiceCreator singletonBarrierCreator =
         new ClusteredSingletonServiceCreator();
     target
         .addService(
             CLUSTERED_SINGLETON_CAPABILITY.getCapabilityServiceName().append("creator"),
             singletonBarrierCreator)
         .addDependency(
             context.getCapabilityServiceName(
                 SingletonPolicy.CAPABILITY_NAME, SingletonPolicy.class),
             SingletonPolicy.class,
             singletonBarrierCreator.getSingletonPolicy())
         .install();
   }
 }
  @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();
              Map<InetSocketAddress, String> map = modcluster.getProxyInfo();
              ROOT_LOGGER.debugf("Mod_cluster ProxyInfo %s", map);
              if (!map.isEmpty()) {
                final ModelNode result = new ModelNode();
                Object[] addr = map.keySet().toArray();
                for (int i = 0; i < addr.length; i++) {
                  InetSocketAddress address = (InetSocketAddress) addr[i];
                  result.add(address.getHostName() + ":" + address.getPort());
                  result.add(map.get(addr[i]));
                }
                context.getResult().set(result);
              }

              context.stepCompleted();
            }
          },
          OperationContext.Stage.RUNTIME);
    }

    context.stepCompleted();
  }
  /** {@inheritDoc} */
  @Override
  public void performBoottime(
      OperationContext context,
      ModelNode operation,
      ModelNode model,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> newControllers)
      throws OperationFailedException {

    // 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(
                SimpleSubsystemDeploymentProcessor.PHASE,
                SimpleSubsystemDeploymentProcessor.PRIORITY,
                new SimpleSubsystemDeploymentProcessor());
          }
        },
        OperationContext.Stage.RUNTIME);

    context.getServiceTarget().addService(SimpleService.NAME, new SimpleService()).install();
  }
  @Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    ModelNode newValue = operation.require(CacheContainerResource.PROTO_URL.getName());
    String urlString = newValue.asString();

    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    final String cacheContainerName = address.getElement(address.size() - 1).getValue();
    final ServiceController<?> controller =
        context
            .getServiceRegistry(false)
            .getService(EmbeddedCacheManagerService.getServiceName(cacheContainerName));

    EmbeddedCacheManager cacheManager = (EmbeddedCacheManager) controller.getValue();
    ProtobufMetadataManager protoManager =
        cacheManager.getGlobalComponentRegistry().getComponent(ProtobufMetadataManager.class);
    if (protoManager != null) {
      try {
        URL url = new URL(urlString);
        protoManager.registerProtofile(url.openStream());
      } catch (Exception e) {
        throw new OperationFailedException(
            new ModelNode().set(MESSAGES.failedToInvokeOperation(e.getLocalizedMessage())));
      }
    }
    context.stepCompleted();
  }
    @Override
    public void execute(OperationContext context, ModelNode operation)
        throws OperationFailedException {
      final String attribute = operation.require(NAME).asString();
      final SensitivityClassificationResource resource =
          (SensitivityClassificationResource) context.readResource(PathAddress.EMPTY_ADDRESS);
      final AbstractSensitivity classification = resource.classification;
      Boolean result = null;
      if (attribute.equals(DEFAULT_REQUIRES_ADDRESSABLE.getName())) {
        result = classification.isDefaultRequiresAccessPermission();
      } else if (attribute.equals(DEFAULT_REQUIRES_READ.getName())) {
        result = classification.isDefaultRequiresReadPermission();
      } else if (attribute.equals(DEFAULT_REQUIRES_WRITE.getName())) {
        result = classification.isDefaultRequiresWritePermission();
      } else if (attribute.equals(CONFIGURED_REQUIRES_ADDRESSABLE.getName())) {
        result = classification.getConfiguredRequiresAccessPermission();
      } else if (attribute.equals(CONFIGURED_REQUIRES_READ.getName())) {
        result = classification.getConfiguredRequiresReadPermission();
      } else if (attribute.equals(CONFIGURED_REQUIRES_WRITE.getName())) {
        result = classification.getConfiguredRequiresWritePermission();
      } else {
        // TODO i18n
        throw new IllegalStateException();
      }

      context.getResult();
      if (result != null) {
        context.getResult().set(result);
      }
      context.stepCompleted();
    }
Example #10
0
  @Override
  protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
      throws OperationFailedException {

    ServiceRegistry registry = context.getServiceRegistry(false);
    final ServiceName serviceName =
        MessagingServices.getActiveMQServiceName(
            PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    ServiceController<?> service = registry.getService(serviceName);
    if (service != null) {
      context.reloadRequired();
    } else {
      final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
      final String name = address.getLastElement().getValue();

      final ServiceTarget target = context.getServiceTarget();
      if (model.hasDefined(JGROUPS_CHANNEL.getName())) {
        // nothing to do, in that case, the clustering.jgroups subsystem will have setup the stack
      } else if (model.hasDefined(RemoteTransportDefinition.SOCKET_BINDING.getName())) {
        final GroupBindingService bindingService = new GroupBindingService();
        target
            .addService(
                GroupBindingService.getBroadcastBaseServiceName(serviceName).append(name),
                bindingService)
            .addDependency(
                SocketBinding.JBOSS_BINDING_NAME.append(model.get(SOCKET_BINDING).asString()),
                SocketBinding.class,
                bindingService.getBindingRef())
            .install();
      }
    }
  }
  @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);
  }
Example #12
0
  @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
 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 {
   PathAddress address =
       context.getCurrentAddress().append(BinaryTableResourceDefinition.PATH);
   ModelNode table = Operations.getAttributeValue(operation);
   for (Class<? extends org.jboss.as.clustering.controller.Attribute> attributeClass :
       Arrays.asList(
           BinaryTableResourceDefinition.Attribute.class,
           TableResourceDefinition.Attribute.class)) {
     for (org.jboss.as.clustering.controller.Attribute attribute :
         attributeClass.getEnumConstants()) {
       ModelNode writeAttributeOperation =
           Operations.createWriteAttributeOperation(
               address, attribute, table.get(attribute.getDefinition().getName()));
       context.addStep(
           writeAttributeOperation,
           context
               .getResourceRegistration()
               .getAttributeAccess(
                   PathAddress.pathAddress(BinaryTableResourceDefinition.PATH),
                   attribute.getDefinition().getName())
               .getWriteHandler(),
           context.getCurrentStage());
     }
   }
 }
  @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))) {
      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);
    }
  }
  @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();
  }
Example #17
0
  void removeRuntimeServices(OperationContext context, ModelNode operation, ModelNode model)
      throws OperationFailedException {
    // get container and cache addresses
    final PathAddress cacheAddress = getCacheAddressFromOperation(operation);
    final PathAddress containerAddress = getCacheContainerAddressFromOperation(operation);
    // get container and cache names
    final String cacheName = cacheAddress.getLastElement().getValue();
    final String containerName = containerAddress.getLastElement().getValue();

    // remove all services started by CacheAdd, in reverse order
    // remove the binder service
    ModelNode resolvedValue = null;
    final String jndiNameString =
        (resolvedValue = CommonAttributes.JNDI_NAME.resolveModelAttribute(context, model))
                .isDefined()
            ? resolvedValue.asString()
            : null;
    final String jndiName =
        InfinispanJndiName.createCacheJndiNameOrDefault(jndiNameString, containerName, cacheName);
    ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
    context.removeService(bindInfo.getBinderServiceName());
    // remove the CacheService instance
    context.removeService(CacheService.getServiceName(containerName, cacheName));
    // remove the cache configuration service
    context.removeService(CacheConfigurationService.getServiceName(containerName, cacheName));

    log.debugf("cache %s removed for container %s", cacheName, containerName);
  }
  @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);
              final ModCluster modcluster = (ModCluster) controller.getValue();
              ROOT_LOGGER.debugf("remove-proxy: %s", operation);

              final Proxy proxy = new Proxy(operation);
              modcluster.removeProxy(proxy.host, proxy.port);

              context.completeStep(
                  new OperationContext.RollbackHandler() {
                    @Override
                    public void handleRollback(OperationContext context, ModelNode operation) {
                      // TODO What if mod_cluster was never aware of this proxy?
                      modcluster.addProxy(proxy.host, proxy.port);
                    }
                  });
            }
          },
          OperationContext.Stage.RUNTIME);
    }

    context.stepCompleted();
  }
  @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"));
    }
  }
  /*
   * (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();
  }
Example #21
0
  @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();
  }
  /** {@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;
  }
  @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);
  }
Example #24
0
  @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();
              ROOT_LOGGER.debugf("add-proxy: %s", operation);

              Proxy proxy = new Proxy(operation);
              modcluster.addProxy(proxy.host, proxy.port);

              // TODO AS7-5695 handle rollback
              context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
            }
          },
          OperationContext.Stage.RUNTIME);
    }

    context.stepCompleted();
  }
    /** {@inheritDoc} */
    @Override
    public void execute(OperationContext context, ModelNode operation)
        throws OperationFailedException {
      final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
      final PathElement element = address.getLastElement();

      context.addStep(
          new OperationStepHandler() {
            @Override
            public void execute(final OperationContext context, final ModelNode operation)
                throws OperationFailedException {
              final ModelNode result = context.getResult();
              final ServiceController<?> controller =
                  context
                      .getServiceRegistry(false)
                      .getRequiredService(SOCKET_BINDING.append(element.getValue()));
              if (controller != null && controller.getState() == ServiceController.State.UP) {
                final SocketBinding binding = SocketBinding.class.cast(controller.getValue());
                AbstractBindingMetricsHandler.this.execute(operation, binding, result);
              } else {
                result.set(getNoMetrics());
              }

              context.stepCompleted();
            }
          },
          OperationContext.Stage.RUNTIME);

      context.stepCompleted();
    }
    @Override
    public void execute(final OperationContext context, final ModelNode operation)
        throws OperationFailedException {
      context.readResource(PathAddress.EMPTY_ADDRESS, false);
      final String group = getServerGroupName(operation);
      context.addStep(
          new OperationStepHandler() {
            @Override
            public void execute(OperationContext context, ModelNode operation)
                throws OperationFailedException {
              if (group != null) {
                final ModelNode model =
                    Resource.Tools.readModel(
                        context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, true));
                for (String server : getServersForGroup(model, group)) {
                  serverInventory.stopServer(server, TIMEOUT);
                }
              } else {
                serverInventory.stopServers(TIMEOUT);
              }
              context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
            }
          },
          Stage.RUNTIME);

      context.stepCompleted();
    }
Example #27
0
 @Override
 public void execute(OperationContext context, ModelNode operation)
     throws OperationFailedException {
   context.removeResource(PathAddress.EMPTY_ADDRESS);
   reloadRequiredStep(context);
   context.stepCompleted();
 }
 @Override
 public void execute(OperationContext context, ModelNode operation)
     throws OperationFailedException {
   context.readResource(PathAddress.EMPTY_ADDRESS, false);
   final ModelNode model =
       Resource.Tools.readModel(context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, true));
   final String group = getServerGroupName(operation);
   context.addStep(
       new OperationStepHandler() {
         @Override
         public void execute(OperationContext context, ModelNode operation)
             throws OperationFailedException {
           Map<String, ProcessInfo> processes = serverInventory.determineRunningProcesses(true);
           final Set<String> serversInGroup = getServersForGroup(model, group);
           for (String serverName : processes.keySet()) {
             final String serverModelName = serverInventory.getProcessServerName(serverName);
             if (group == null || serversInGroup.contains(serverModelName)) {
               serverInventory.restartServer(serverModelName, TIMEOUT, model);
             }
           }
           context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
         }
       },
       Stage.RUNTIME);
   context.stepCompleted();
 }
  void updatePoolService(final OperationContext context, final ModelNode model)
      throws OperationFailedException {

    final ModelNode poolName = poolAttribute.resolveModelAttribute(context, model);

    final ServiceRegistry serviceRegistry = context.getServiceRegistry(true);
    ServiceController existingDefaultPoolConfigService =
        serviceRegistry.getService(poolConfigServiceName);
    // if a default MDB pool is already installed, then remove it first
    if (existingDefaultPoolConfigService != null) {
      context.removeService(existingDefaultPoolConfigService);
    }

    if (poolName.isDefined()) {
      // now install default pool config service which points to an existing pool config service
      final ValueInjectionService<PoolConfig> newDefaultPoolConfigService =
          new ValueInjectionService<PoolConfig>();
      ServiceController<?> newController =
          context
              .getServiceTarget()
              .addService(poolConfigServiceName, newDefaultPoolConfigService)
              .addDependency(
                  PoolConfigService.EJB_POOL_CONFIG_BASE_SERVICE_NAME.append(poolName.asString()),
                  PoolConfig.class,
                  newDefaultPoolConfigService.getInjector())
              .install();
    }
  }
  void launchServices(
      final OperationContext context,
      final PathAddress pathAddress,
      final ModelNode model,
      final ServiceVerificationHandler verificationHandler,
      final List<ServiceController<?>> newControllers)
      throws OperationFailedException {
    Handler newHandler = new Handler();

    newHandler.setClazz(
        HandlerResourceDefinition.CLASS.resolveModelAttribute(context, model).asString());

    ModelNode handler = Resource.Tools.readModel(context.readResourceFromRoot(pathAddress));

    if (handler.hasDefined(COMMON_HANDLER_PARAMETER.getName())) {
      for (ModelNode handlerParameter : handler.get(COMMON_HANDLER_PARAMETER.getName()).asList()) {
        Property property = handlerParameter.asProperty();
        String paramName = property.getName();
        String paramValue =
            HandlerParameterResourceDefinition.VALUE
                .resolveModelAttribute(context, property.getValue())
                .asString();

        KeyValueType kv = new KeyValueType();

        kv.setKey(paramName);
        kv.setValue(paramValue);

        newHandler.add(kv);
      }
    }

    SAMLHandlerService service = new SAMLHandlerService(newHandler);
    PathElement providerAlias = pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement();

    ServiceTarget serviceTarget = context.getServiceTarget();
    ServiceBuilder<SAMLHandlerService> serviceBuilder =
        serviceTarget.addService(
            createServiceName(providerAlias.getValue(), newHandler.getClazz()), service);
    ServiceName serviceName;

    if (providerAlias.getKey().equals(IDENTITY_PROVIDER.getName())) {
      serviceName = IdentityProviderService.createServiceName(providerAlias.getValue());
    } else {
      serviceName = ServiceProviderService.createServiceName(providerAlias.getValue());
    }

    serviceBuilder.addDependency(
        serviceName, EntityProviderService.class, service.getEntityProviderService());

    ServiceController<SAMLHandlerService> controller =
        serviceBuilder
            .addListener(verificationHandler)
            .setInitialMode(ServiceController.Mode.PASSIVE)
            .install();

    if (newControllers != null) {
      newControllers.add(controller);
    }
  }