public ModelNode getDomainModel() {
   if (domainModel == null) {
     domainModel =
         Resource.Tools.readModel(context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, true));
   }
   return domainModel;
 }
 @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 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);
    }
  }
Ejemplo n.º 4
0
 private static boolean isEJBRemoteConnectorInstalled(final OperationContext context) {
   final ModelNode ejbSubsystemFullModel =
       Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));
   return ejbSubsystemFullModel.hasDefined(EJB3SubsystemModel.SERVICE)
       && ejbSubsystemFullModel
           .get(EJB3SubsystemModel.SERVICE)
           .hasDefined(EJB3SubsystemModel.REMOTE);
 }
Ejemplo n.º 5
0
 /**
  * Make any runtime changes necessary to effect the changes indicated by the given {@code
  * operation}. E
  *
  * <p>It constructs a MailSessionService that provides mail session and registers it to Naming
  * service.
  *
  * @param context the operation context
  * @param operation the operation being executed
  * @param model persistent configuration model node that corresponds to the address of {@code
  *     operation}
  * @param verificationHandler step handler that can be added as a listener to any new services
  *     installed in order to validate the services installed correctly during the {@link
  *     org.jboss.as.controller.OperationContext.Stage#VERIFY VERIFY stage}
  * @param controllers holder for the {@link org.jboss.msc.service.ServiceController} for any new
  *     services installed by the method. The method should add the {@code ServiceController} for
  *     any new services to this list. If the overall operation needs to be rolled back, the list
  *     will be used in {@link #rollbackRuntime(org.jboss.as.controller.OperationContext,
  *     org.jboss.dmr.ModelNode, org.jboss.dmr.ModelNode, java.util.List)} to automatically removed
  *     the newly added services
  * @throws org.jboss.as.controller.OperationFailedException if {@code operation} is invalid or
  *     updating the runtime otherwise fails
  */
 @Override
 protected void performRuntime(
     OperationContext context,
     ModelNode operation,
     ModelNode model,
     ServiceVerificationHandler verificationHandler,
     List<ServiceController<?>> controllers)
     throws OperationFailedException {
   final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
   ModelNode fullTree = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));
   installRuntimeServices(context, address, fullTree, verificationHandler, controllers);
 }
Ejemplo n.º 6
0
  @Override
  protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
      throws OperationFailedException {
    super.performRuntime(context, operation, model);

    PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    String hornetqServerName = address.getElement(address.size() - 2).getValue();
    String acceptorName = address.getLastElement().getValue();
    final ModelNode fullModel =
        Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));

    launchServices(context, hornetqServerName, acceptorName, fullModel);
  }
Ejemplo n.º 7
0
 @Override
 protected void performRuntime(
     OperationContext context,
     ModelNode operation,
     ModelNode localModel,
     ServiceVerificationHandler verificationHandler,
     List<ServiceController<?>> newControllers)
     throws OperationFailedException {
   // Because we use child resources in a read-only manner to configure the cache container,
   // replace the local model with the full model
   ModelNode model = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));
   newControllers.addAll(installRuntimeServices(context, operation, model, verificationHandler));
 }
 @Override
 protected void performRuntime(
     OperationContext context,
     ModelNode operation,
     ModelNode model,
     final ServiceVerificationHandler verificationHandler,
     final List<ServiceController<?>> newControllers)
     throws OperationFailedException {
   PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
   final String federationName = address.getLastElement().getValue();
   ModelNode partitionManager = Resource.Tools.readModel(context.readResource(EMPTY_ADDRESS));
   createPartitionManagerService(
       context, federationName, partitionManager, verificationHandler, newControllers, false);
 }
Ejemplo n.º 9
0
 public ModelNode readModel(final PathAddress requestAddress) {
   final PathAddress address = activeStep.address.append(requestAddress);
   assert isControllingThread();
   Stage currentStage = this.currentStage;
   if (currentStage == null) {
     throw MESSAGES.operationAlreadyComplete();
   }
   Resource model = this.model;
   for (final PathElement element : address) {
     model = requireChild(model, element, address);
   }
   // recursively read the model
   return Resource.Tools.readModel(model);
 }
Ejemplo n.º 10
0
  @Override
  protected void performRuntime(
      OperationContext context,
      ModelNode operation,
      ModelNode model,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> newControllers)
      throws OperationFailedException {

    final ModelNode fullModel =
        Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));
    // Use ModClusterExtension.configurationPath here so if we change the PathElement components,
    // we don't have to change this code
    final ModelNode unresolvedConfig =
        fullModel.get(
            ModClusterExtension.configurationPath.getKey(),
            ModClusterExtension.configurationPath.getValue());
    final ModelNode resolvedConfig = resolveConfig(context, unresolvedConfig);

    // Add mod_cluster service
    final ModClusterService service = new ModClusterService(resolvedConfig);
    final ServiceBuilder<ModCluster> serviceBuilder =
        context
            .getServiceTarget()
            .addService(ModClusterService.NAME, service)
            .addDependency(WebSubsystemServices.JBOSS_WEB, WebServer.class, service.getWebServer())
            .addDependency(
                SocketBindingManager.SOCKET_BINDING_MANAGER,
                SocketBindingManager.class,
                service.getBindingManager())
            .addListener(verificationHandler)
            .setInitialMode(Mode.ACTIVE);
    final ModelNode bindingRefNode =
        resolvedConfig.get(ModClusterConfigResourceDefinition.ADVERTISE_SOCKET.getName());
    final String bindingRef = bindingRefNode.isDefined() ? bindingRefNode.asString() : null;
    if (bindingRef != null) {
      serviceBuilder.addDependency(
          SocketBinding.JBOSS_BINDING_NAME.append(bindingRef),
          SocketBinding.class,
          service.getBinding());
    }

    newControllers.add(serviceBuilder.install());
  }
Ejemplo n.º 11
0
 @Override
 public void execute(OperationContext context, ModelNode operation)
     throws OperationFailedException {
   final List<ServiceController<?>> newControllers = new ArrayList<ServiceController<?>>();
   final String realmName = ManagementUtil.getSecurityRealmName(operation);
   final ModelNode model =
       Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));
   SecurityRealmAddHandler.INSTANCE.installServices(
       context, realmName, model, new ServiceVerificationHandler(), newControllers);
   context.completeStep(
       new OperationContext.RollbackHandler() {
         @Override
         public void handleRollback(OperationContext context, ModelNode operation) {
           for (ServiceController<?> sc : newControllers) {
             context.removeService(sc);
           }
         }
       });
 }
Ejemplo n.º 12
0
  @Override
  protected void performRuntime(
      OperationContext context,
      ModelNode operation,
      ModelNode model,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> newControllers)
      throws OperationFailedException {

    // Because we use child resources in a read-only manner to configure the cache, replace the
    // local model with the full model
    ModelNode cacheModel =
        Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));

    // we also need the containerModel
    PathAddress containerAddress = getCacheContainerAddressFromOperation(operation);
    ModelNode containerModel = context.readResourceFromRoot(containerAddress).getModel();

    // install the services from a reusable method
    newControllers.addAll(
        this.installRuntimeServices(
            context, operation, containerModel, cacheModel, verificationHandler));
  }
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {

    Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
    final ModelNode model = Resource.Tools.readModel(resource);

    recordCapabilitiesAndRequirements(context, operation, resource);

    performRemove(context, operation, model);

    if (requiresRuntime(context)) {
      context.addStep(
          new OperationStepHandler() {
            public void execute(OperationContext context, ModelNode operation)
                throws OperationFailedException {
              performRuntime(context, operation, model);

              context.completeStep(
                  new OperationContext.RollbackHandler() {
                    @Override
                    public void handleRollback(OperationContext context, ModelNode operation) {
                      try {
                        recoverServices(context, operation, model);
                      } catch (Exception e) {
                        MGMT_OP_LOGGER.errorRevertingOperation(
                            e,
                            getClass().getSimpleName(),
                            operation.require(ModelDescriptionConstants.OP).asString(),
                            context.getCurrentAddress());
                      }
                    }
                  });
            }
          },
          OperationContext.Stage.RUNTIME);
    }
  }
    @Override
    public void execute(final OperationContext context, final 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 {
              final String hostName = model.get(HOST).keys().iterator().next();
              final ModelNode serverConfig = model.get(HOST, hostName).get(SERVER_CONFIG);
              final Set<String> serversInGroup = getServersForGroup(model, group);
              if (serverConfig.isDefined()) {
                for (Property config : serverConfig.asPropertyList()) {
                  final ServerStatus status =
                      serverInventory.determineServerStatus(config.getName());
                  if (status != ServerStatus.STARTING && status != ServerStatus.STARTED) {
                    if (group == null || serversInGroup.contains(config.getName())) {
                      if (status != ServerStatus.STOPPED) {
                        serverInventory.stopServer(config.getName(), TIMEOUT);
                      }
                      serverInventory.startServer(config.getName(), model);
                    }
                  }
                }
              }
              context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
            }
          },
          Stage.RUNTIME);

      context.stepCompleted();
    }
Ejemplo n.º 15
0
  @Override
  protected void performRuntime(
      OperationContext context,
      ModelNode operation,
      ModelNode model,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> newControllers)
      throws OperationFailedException {
    // Because we use child resources in a read-only manner to configure the cache container,
    // replace the local model with the full model
    model = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));

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

    String defaultCache = model.require(ModelKeys.DEFAULT_CACHE).asString();

    boolean hasTransport =
        model.hasDefined(ModelKeys.TRANSPORT)
            && model.get(ModelKeys.TRANSPORT).hasDefined(ModelKeys.TRANSPORT_NAME);
    Transport transportConfig = hasTransport ? new Transport() : null;
    EmbeddedCacheManagerDependencies dependencies =
        new EmbeddedCacheManagerDependencies(transportConfig);

    ServiceName[] aliases = null;
    if (model.hasDefined(ModelKeys.ALIASES)) {
      List<ModelNode> list = operation.get(ModelKeys.ALIASES).asList();
      aliases = new ServiceName[list.size()];
      for (int i = 0; i < list.size(); i++) {
        aliases[i] = EmbeddedCacheManagerService.getServiceName(list.get(i).asString());
      }
    }

    ServiceTarget target = context.getServiceTarget();
    ServiceName serviceName = EmbeddedCacheManagerService.getServiceName(name);
    ServiceBuilder<EmbeddedCacheManager> containerBuilder =
        target
            .addService(
                serviceName, new EmbeddedCacheManagerService(name, defaultCache, dependencies))
            .addDependency(
                DependencyType.OPTIONAL,
                ServiceName.JBOSS.append("mbean", "server"),
                MBeanServer.class,
                dependencies.getMBeanServerInjector())
            .addAliases(aliases)
            .setInitialMode(ServiceController.Mode.ON_DEMAND);

    String jndiName =
        (model.hasDefined(ModelKeys.JNDI_NAME)
                ? InfinispanJndiName.toJndiName(model.get(ModelKeys.JNDI_NAME).asString())
                : InfinispanJndiName.defaultCacheContainerJndiName(name))
            .getAbsoluteName();
    ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);

    BinderService binder = new BinderService(bindInfo.getBindName());
    ServiceBuilder<ManagedReferenceFactory> binderBuilder =
        target
            .addService(bindInfo.getBinderServiceName(), binder)
            .addAliases(ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(jndiName))
            .addDependency(
                serviceName,
                CacheContainer.class,
                new ManagedReferenceInjector<CacheContainer>(binder.getManagedObjectInjector()))
            .addDependency(
                bindInfo.getParentContextServiceName(),
                ServiceBasedNamingStore.class,
                binder.getNamingStoreInjector())
            .setInitialMode(ServiceController.Mode.ON_DEMAND);
    newControllers.add(binderBuilder.install());

    if (hasTransport) {
      String stack = null;
      ModelNode transport = model.get(ModelKeys.TRANSPORT, ModelKeys.TRANSPORT_NAME);
      if (transport.hasDefined(ModelKeys.STACK)) {
        stack = transport.get(ModelKeys.STACK).asString();
      }
      if (transport.hasDefined(ModelKeys.LOCK_TIMEOUT)) {
        transportConfig.setLockTimeout(transport.get(ModelKeys.LOCK_TIMEOUT).asLong());
      }
      addExecutorDependency(
          containerBuilder, transport, ModelKeys.EXECUTOR, transportConfig.getExecutorInjector());

      ServiceName channelServiceName = ChannelService.getServiceName(name);
      containerBuilder.addDependency(
          channelServiceName, Channel.class, transportConfig.getChannelInjector());

      InjectedValue<ChannelFactory> channelFactory = new InjectedValue<ChannelFactory>();
      ServiceBuilder<Channel> channelBuilder =
          target
              .addService(channelServiceName, new ChannelService(name, channelFactory))
              .addDependency(
                  ChannelFactoryService.getServiceName(stack), ChannelFactory.class, channelFactory)
              .setInitialMode(ServiceController.Mode.ON_DEMAND);
      newControllers.add(channelBuilder.install());
    }

    addExecutorDependency(
        containerBuilder,
        model,
        ModelKeys.LISTENER_EXECUTOR,
        dependencies.getListenerExecutorInjector());
    addScheduledExecutorDependency(
        containerBuilder,
        model,
        ModelKeys.EVICTION_EXECUTOR,
        dependencies.getEvictionExecutorInjector());
    addScheduledExecutorDependency(
        containerBuilder,
        model,
        ModelKeys.REPLICATION_QUEUE_EXECUTOR,
        dependencies.getReplicationQueueExecutorInjector());

    newControllers.add(containerBuilder.install());

    log.debugf("%s cache container installed", name);
  }
Ejemplo n.º 16
0
  /**
   * Make any runtime changes necessary to effect the changes indicated by the given {@code
   * operation}. E
   *
   * <p>It constructs a MailSessionService that provides mail session and registers it to Naming
   * service.
   *
   * @param context the operation context
   * @param operation the operation being executed
   * @param model persistent configuration model node that corresponds to the address of {@code
   *     operation}
   * @param verificationHandler step handler that can be added as a listener to any new services
   *     installed in order to validate the services installed correctly during the {@link
   *     org.jboss.as.controller.OperationContext.Stage#VERIFY VERIFY stage}
   * @param controllers holder for the {@link org.jboss.msc.service.ServiceController} for any new
   *     services installed by the method. The method should add the {@code ServiceController} for
   *     any new services to this list. If the overall operation needs to be rolled back, the list
   *     will be used in {@link #rollbackRuntime(org.jboss.as.controller.OperationContext,
   *     org.jboss.dmr.ModelNode, org.jboss.dmr.ModelNode, java.util.List)} to automatically removed
   *     the newly added services
   * @throws org.jboss.as.controller.OperationFailedException if {@code operation} is invalid or
   *     updating the runtime otherwise fails
   */
  @Override
  protected void performRuntime(
      OperationContext context,
      ModelNode operation,
      ModelNode model,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> controllers)
      throws OperationFailedException {
    final String jndiName = getJndiName(operation);
    final ServiceTarget serviceTarget = context.getServiceTarget();

    ModelNode fullTree = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));
    final MailSessionConfig config = from(context, fullTree);
    final MailSessionService service = new MailSessionService(config);
    final ServiceName serviceName = SERVICE_NAME_BASE.append(jndiName);
    final ServiceBuilder<?> mailSessionBuilder = serviceTarget.addService(serviceName, service);
    addOutboundSocketDependency(service, mailSessionBuilder, config.getImapServer());
    addOutboundSocketDependency(service, mailSessionBuilder, config.getPop3Server());
    addOutboundSocketDependency(service, mailSessionBuilder, config.getSmtpServer());
    for (CustomServerConfig server : config.getCustomServers()) {
      if (server.getOutgoingSocketBinding() != null) {
        addOutboundSocketDependency(service, mailSessionBuilder, server);
      }
    }

    final ManagedReferenceFactory valueManagedReferenceFactory =
        new ContextListAndJndiViewManagedReferenceFactory() {

          @Override
          public String getJndiViewInstanceValue() {
            return String.valueOf(getReference().getInstance());
          }

          @Override
          public String getInstanceClassName() {
            final Object value = getReference().getInstance();
            return value != null
                ? value.getClass().getName()
                : ContextListManagedReferenceFactory.DEFAULT_INSTANCE_CLASS_NAME;
          }

          @Override
          public ManagedReference getReference() {
            return new ValueManagedReference(new ImmediateValue<Object>(service.getValue()));
          }
        };
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
    final BinderService binderService = new BinderService(bindInfo.getBindName());
    final ServiceBuilder<?> binderBuilder =
        serviceTarget
            .addService(bindInfo.getBinderServiceName(), binderService)
            .addInjection(binderService.getManagedObjectInjector(), valueManagedReferenceFactory)
            .addDependency(
                bindInfo.getParentContextServiceName(),
                ServiceBasedNamingStore.class,
                binderService.getNamingStoreInjector())
            .addListener(
                new AbstractServiceListener<Object>() {
                  public void transition(
                      final ServiceController<? extends Object> controller,
                      final ServiceController.Transition transition) {
                    switch (transition) {
                      case STARTING_to_UP:
                        {
                          MailLogger.ROOT_LOGGER.boundMailSession(jndiName);
                          break;
                        }
                      case START_REQUESTED_to_DOWN:
                        {
                          MailLogger.ROOT_LOGGER.unboundMailSession(jndiName);
                          break;
                        }
                      case REMOVING_to_REMOVED:
                        {
                          MailLogger.ROOT_LOGGER.removedMailSession(jndiName);
                          break;
                        }
                    }
                  }
                });

    mailSessionBuilder
        .setInitialMode(ServiceController.Mode.ACTIVE)
        .addListener(verificationHandler);
    binderBuilder.setInitialMode(ServiceController.Mode.ACTIVE).addListener(verificationHandler);
    controllers.add(mailSessionBuilder.install());
    controllers.add(binderBuilder.install());
  }
Ejemplo n.º 17
0
  @Override
  protected void performBoottime(
      OperationContext context,
      ModelNode baseOperation,
      ModelNode model,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> newControllers)
      throws OperationFailedException {
    ModelNode fullModel = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));
    final ModelNode config = resolveConfiguration(context, fullModel.get(Constants.CONFIGURATION));
    final String defaultVirtualServer =
        WebDefinition.DEFAULT_VIRTUAL_SERVER.resolveModelAttribute(context, fullModel).asString();

    final boolean useNative =
        WebDefinition.NATIVE.resolveModelAttribute(context, fullModel).asBoolean();
    final ModelNode instanceIdModel =
        WebDefinition.INSTANCE_ID.resolveModelAttribute(context, fullModel);
    final String instanceId = instanceIdModel.isDefined() ? instanceIdModel.asString() : null;

    context.addStep(
        new AbstractDeploymentChainStep() {
          @Override
          protected void execute(DeploymentProcessorTarget processorTarget) {

            final SharedWebMetaDataBuilder sharedWebBuilder =
                new SharedWebMetaDataBuilder(config.clone());
            final SharedTldsMetaDataBuilder sharedTldsBuilder =
                new SharedTldsMetaDataBuilder(config.clone());

            processorTarget.addDeploymentProcessor(
                WebExtension.SUBSYSTEM_NAME,
                Phase.STRUCTURE,
                Phase.STRUCTURE_REGISTER_JBOSS_ALL_XML_PARSER,
                new JBossAllXmlParserRegisteringProcessor<JBossWebMetaData>(
                    WebJBossAllParser.ROOT_ELEMENT,
                    WebJBossAllParser.ATTACHMENT_KEY,
                    new WebJBossAllParser()));
            processorTarget.addDeploymentProcessor(
                WebExtension.SUBSYSTEM_NAME,
                Phase.STRUCTURE,
                Phase.STRUCTURE_WAR_DEPLOYMENT_INIT,
                new WarDeploymentInitializingProcessor());
            processorTarget.addDeploymentProcessor(
                WebExtension.SUBSYSTEM_NAME,
                Phase.STRUCTURE,
                Phase.STRUCTURE_WAR,
                new WarStructureDeploymentProcessor(sharedWebBuilder.create(), sharedTldsBuilder));
            processorTarget.addDeploymentProcessor(
                WebExtension.SUBSYSTEM_NAME,
                Phase.PARSE,
                Phase.PARSE_WEB_DEPLOYMENT,
                new WebParsingDeploymentProcessor());
            processorTarget.addDeploymentProcessor(
                WebExtension.SUBSYSTEM_NAME,
                Phase.PARSE,
                Phase.PARSE_WEB_DEPLOYMENT_FRAGMENT,
                new WebFragmentParsingDeploymentProcessor());
            processorTarget.addDeploymentProcessor(
                WebExtension.SUBSYSTEM_NAME,
                Phase.PARSE,
                Phase.PARSE_JBOSS_WEB_DEPLOYMENT,
                new JBossWebParsingDeploymentProcessor());
            processorTarget.addDeploymentProcessor(
                WebExtension.SUBSYSTEM_NAME,
                Phase.PARSE,
                Phase.PARSE_TLD_DEPLOYMENT,
                new TldParsingDeploymentProcessor());
            processorTarget.addDeploymentProcessor(
                WebExtension.SUBSYSTEM_NAME,
                Phase.PARSE,
                Phase.PARSE_ANNOTATION_WAR,
                new WarAnnotationDeploymentProcessor());
            processorTarget.addDeploymentProcessor(
                WebExtension.SUBSYSTEM_NAME,
                Phase.PARSE,
                Phase.PARSE_WEB_COMPONENTS,
                new WebComponentProcessor());
            processorTarget.addDeploymentProcessor(
                WebExtension.SUBSYSTEM_NAME,
                Phase.PARSE,
                Phase.PARSE_EAR_CONTEXT_ROOT,
                new EarContextRootProcessor());
            processorTarget.addDeploymentProcessor(
                WebExtension.SUBSYSTEM_NAME,
                Phase.PARSE,
                Phase.PARSE_WEB_MERGE_METADATA,
                new WarMetaDataProcessor());
            processorTarget.addDeploymentProcessor(
                WebExtension.SUBSYSTEM_NAME,
                Phase.PARSE,
                Phase.PARSE_WEB_INITIALIZE_IN_ORDER,
                new WebInitializeInOrderProcessor(defaultVirtualServer));

            processorTarget.addDeploymentProcessor(
                WebExtension.SUBSYSTEM_NAME,
                Phase.DEPENDENCIES,
                Phase.DEPENDENCIES_WAR_MODULE,
                new WarClassloadingDependencyProcessor());

            processorTarget.addDeploymentProcessor(
                WebExtension.SUBSYSTEM_NAME,
                Phase.INSTALL,
                Phase.INSTALL_SERVLET_INIT_DEPLOYMENT,
                new ServletContainerInitializerDeploymentProcessor());
            processorTarget.addDeploymentProcessor(
                WebExtension.SUBSYSTEM_NAME,
                Phase.INSTALL,
                Phase.INSTALL_WAR_DEPLOYMENT,
                new WarDeploymentProcessor(defaultVirtualServer));
          }
        },
        OperationContext.Stage.RUNTIME);

    final ServiceTarget target = context.getServiceTarget();
    final WebServerService service =
        new WebServerService(defaultVirtualServer, useNative, instanceId, TEMP_DIR);
    newControllers.add(
        target
            .addService(WebSubsystemServices.JBOSS_WEB, service)
            .addDependency(
                PathManagerService.SERVICE_NAME,
                PathManager.class,
                service.getPathManagerInjector())
            .addDependency(
                DependencyType.OPTIONAL,
                ServiceName.JBOSS.append("mbean", "server"),
                MBeanServer.class,
                service.getMbeanServer())
            .setInitialMode(Mode.ON_DEMAND)
            .install());

    final DistributedCacheManagerFactory factory =
        new DistributedCacheManagerFactoryService().getValue();
    if (factory != null) {
      final InjectedValue<WebServer> server = new InjectedValue<WebServer>();
      newControllers.add(
          target
              .addService(
                  DistributedCacheManagerFactoryService
                      .JVM_ROUTE_REGISTRY_ENTRY_PROVIDER_SERVICE_NAME,
                  new JvmRouteRegistryEntryProviderService(server))
              .addDependency(WebSubsystemServices.JBOSS_WEB, WebServer.class, server)
              .setInitialMode(Mode.ON_DEMAND)
              .install());
      newControllers.addAll(factory.installServices(target));
    }
  }
Ejemplo n.º 18
0
  static void launchServices(
      final OperationContext context,
      final PathAddress pathAddress,
      final ModelNode model,
      final ServiceVerificationHandler verificationHandler,
      final List<ServiceController<?>> newControllers)
      throws OperationFailedException {
    Handler newHandler = new Handler();

    ModelNode classNameNode = HandlerResourceDefinition.CLASS.resolveModelAttribute(context, model);
    ModelNode codeNode = HandlerResourceDefinition.CODE.resolveModelAttribute(context, model);
    String typeName;

    if (classNameNode.isDefined()) {
      typeName = classNameNode.asString();
    } else if (codeNode.isDefined()) {
      typeName = HandlerTypeEnum.forType(codeNode.asString());
    } else {
      throw PicketLinkLogger.ROOT_LOGGER.federationHandlerTypeNotProvided();
    }

    newHandler.setClazz(typeName);

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

    if (handler.hasDefined(COMMON_HANDLER_PARAMETER.getName())) {
      for (Property handlerParameter :
          handler.get(COMMON_HANDLER_PARAMETER.getName()).asPropertyList()) {
        String paramName = handlerParameter.getName();
        String paramValue =
            HandlerParameterResourceDefinition.VALUE
                .resolveModelAttribute(context, handlerParameter.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());

    if (verificationHandler != null) {
      serviceBuilder.addListener(verificationHandler);
    }

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

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

    if (!context.isBooting()) {
      // a reload is required to get the chain properly updated with the domain model state.
      context.reloadRequired();
    }
  }
Ejemplo n.º 19
0
  @Override
  protected void performRuntime(
      OperationContext context,
      ModelNode operation,
      ModelNode model,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> newControllers)
      throws OperationFailedException {
    // Because we use child resources in a read-only manner to configure the cache, replace the
    // local model with the full model
    model = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));

    // Configuration to hold the operation data
    ConfigurationBuilder builder =
        new ConfigurationBuilder().read(getDefaultConfiguration(this.mode));

    // create a list for dependencies which may need to be added during processing
    List<Dependency<?>> dependencies = new LinkedList<Dependency<?>>();

    // process cache configuration ModelNode describing overrides to defaults
    processModelNode(model, builder, dependencies);

    // get all required addresses, names and service names
    PathAddress cacheAddress = PathAddress.pathAddress(operation.get(OP_ADDR));
    PathAddress containerAddress = cacheAddress.subAddress(0, cacheAddress.size() - 1);
    String cacheName = cacheAddress.getLastElement().getValue();
    String containerName = containerAddress.getLastElement().getValue();
    ServiceName containerServiceName = EmbeddedCacheManagerService.getServiceName(containerName);
    ServiceName cacheServiceName = containerServiceName.append(cacheName);
    ServiceName cacheConfigurationServiceName =
        CacheConfigurationService.getServiceName(containerName, cacheName);

    // get container Model
    Resource rootResource = context.getRootResource();
    ModelNode container = rootResource.navigate(containerAddress).getModel();

    // get default cache of the container and start mode
    String defaultCache = container.require(ModelKeys.DEFAULT_CACHE).asString();
    ServiceController.Mode initialMode =
        model.hasDefined(ModelKeys.START)
            ? StartMode.valueOf(model.get(ModelKeys.START).asString()).getMode()
            : ServiceController.Mode.ON_DEMAND;

    // install the cache configuration service (configures a cache)
    ServiceTarget target = context.getServiceTarget();
    InjectedValue<EmbeddedCacheManager> containerInjection =
        new InjectedValue<EmbeddedCacheManager>();
    CacheConfigurationDependencies cacheConfigurationDependencies =
        new CacheConfigurationDependencies(containerInjection);
    CacheConfigurationService cacheConfigurationService =
        new CacheConfigurationService(cacheName, builder, cacheConfigurationDependencies);

    ServiceBuilder<Configuration> configBuilder =
        target
            .addService(cacheConfigurationServiceName, cacheConfigurationService)
            .addDependency(containerServiceName, EmbeddedCacheManager.class, containerInjection)
            .setInitialMode(ServiceController.Mode.PASSIVE);

    Configuration config = builder.build();
    if (config.invocationBatching().enabled()) {
      cacheConfigurationDependencies
          .getTransactionManagerInjector()
          .inject(BatchModeTransactionManager.getInstance());
    } else if (config.transaction().transactionMode()
        == org.infinispan.transaction.TransactionMode.TRANSACTIONAL) {
      configBuilder.addDependency(
          TxnServices.JBOSS_TXN_TRANSACTION_MANAGER,
          TransactionManager.class,
          cacheConfigurationDependencies.getTransactionManagerInjector());
      if (config.transaction().useSynchronization()) {
        configBuilder.addDependency(
            TxnServices.JBOSS_TXN_SYNCHRONIZATION_REGISTRY,
            TransactionSynchronizationRegistry.class,
            cacheConfigurationDependencies.getTransactionSynchronizationRegistryInjector());
      }
    }

    // add in any additional dependencies resulting from ModelNode parsing
    for (Dependency<?> dependency : dependencies) {
      this.addDependency(configBuilder, dependency);
    }
    // add an alias for the default cache
    if (cacheName.equals(defaultCache)) {
      configBuilder.addAliases(CacheConfigurationService.getServiceName(containerName, null));
    }
    newControllers.add(configBuilder.install());
    log.debugf(
        "Cache configuration service for %s installed for container %s", cacheName, containerName);

    // now install the corresponding cache service (starts a configured cache)
    CacheDependencies cacheDependencies = new CacheDependencies(containerInjection);
    CacheService<Object, Object> cacheService =
        new CacheService<Object, Object>(cacheName, cacheDependencies);

    ServiceBuilder<Cache<Object, Object>> cacheBuilder =
        target
            .addService(cacheServiceName, cacheService)
            .addDependency(cacheConfigurationServiceName)
            .setInitialMode(initialMode);

    if (config.transaction().recovery().enabled()) {
      cacheBuilder.addDependency(
          TxnServices.JBOSS_TXN_ARJUNA_RECOVERY_MANAGER,
          XAResourceRecoveryRegistry.class,
          cacheDependencies.getRecoveryRegistryInjector());
    }

    // add an alias for the default cache
    if (cacheName.equals(defaultCache)) {
      cacheBuilder.addAliases(CacheService.getServiceName(containerName, null));
    }

    if (initialMode == ServiceController.Mode.ACTIVE) {
      cacheBuilder.addListener(verificationHandler);
    }

    newControllers.add(cacheBuilder.install());

    String jndiName =
        (model.hasDefined(ModelKeys.JNDI_NAME)
                ? InfinispanJndiName.toJndiName(model.get(ModelKeys.JNDI_NAME).asString())
                : InfinispanJndiName.defaultCacheJndiName(containerName, cacheName))
            .getAbsoluteName();
    ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);

    BinderService binder = new BinderService(bindInfo.getBindName());
    @SuppressWarnings("rawtypes")
    ServiceBuilder<ManagedReferenceFactory> binderBuilder =
        target
            .addService(bindInfo.getBinderServiceName(), binder)
            .addAliases(ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(jndiName))
            .addDependency(
                cacheServiceName,
                Cache.class,
                new ManagedReferenceInjector<Cache>(binder.getManagedObjectInjector()))
            .addDependency(
                bindInfo.getParentContextServiceName(),
                ServiceBasedNamingStore.class,
                binder.getNamingStoreInjector())
            .setInitialMode(ServiceController.Mode.PASSIVE);
    newControllers.add(binderBuilder.install());

    log.debugf("Cache service for cache %s installed for container %s", cacheName, containerName);
  }