@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();
  }
  @After
  public void after() throws IOException, MgmtOperationException {

    shutdownHttpClient();

    try {
      ModelNode op =
          Util.createEmptyOperation(
              REMOVE,
              PathAddress.pathAddress(SYSTEM_PROPERTY, LogStreamExtension.LOG_MESSAGE_PROP));
      executeOperation(op);
    } finally {
      try {
        ModelNode op =
            Util.createEmptyOperation(
                REMOVE, PathAddress.pathAddress(SUBSYSTEM, LogStreamExtension.SUBSYSTEM_NAME));
        executeOperation(op);
      } finally {
        ModelNode op =
            Util.createEmptyOperation(
                REMOVE, PathAddress.pathAddress(EXTENSION, LogStreamExtension.MODULE_NAME));
        executeOperation(op);
      }
    }
  }
Пример #3
0
  protected void performRuntime(
      OperationContext context,
      ModelNode operation,
      ModelNode model,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> newControllers)
      throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    final String name = address.getLastElement().getValue();
    final ServiceTarget serviceTarget = context.getServiceTarget();
    final ServiceName hqServiceName =
        MessagingServices.getHornetQServiceName(
            PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));

    final ModelNode selectorNode = SELECTOR.resolveModelAttribute(context, model);
    final boolean durable = DURABLE.resolveModelAttribute(context, model).asBoolean();

    final String selector = selectorNode.isDefined() ? selectorNode.asString() : null;
    final ModelNode entries =
        CommonAttributes.DESTINATION_ENTRIES.resolveModelAttribute(context, model);
    final String[] jndiBindings = JMSServices.getJndiBindings(entries);
    installServices(
        verificationHandler,
        newControllers,
        name,
        serviceTarget,
        hqServiceName,
        selector,
        durable,
        jndiBindings);
  }
Пример #4
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();
      }
    }
  }
Пример #5
0
    public void setup(ManagementClient managementClient, String containerId) throws Exception {
      final ModelNode compositeOp = new ModelNode();
      compositeOp.get(OP).set(COMPOSITE);
      compositeOp.get(OP_ADDR).setEmptyList();
      ModelNode updates = compositeOp.get(STEPS);
      PathAddress address =
          PathAddress.pathAddress()
              .append(SUBSYSTEM, "security")
              .append(SECURITY_DOMAIN, getSecurityDomainName());

      updates.add(Util.createAddOperation(address));
      address = address.append(Constants.AUTHENTICATION, Constants.CLASSIC);
      updates.add(Util.createAddOperation(address));

      ModelNode loginModule =
          Util.createAddOperation(address.append(LOGIN_MODULE, RunAsLoginModule.class.getName()));
      loginModule.get(CODE).set(RunAsLoginModule.class.getName());
      loginModule.get(FLAG).set("optional");
      ModelNode moduleOptions = loginModule.get("module-options");
      moduleOptions.get("roleName").set("RunAsLoginModuleRole");

      ModelNode loginModule2 =
          Util.createAddOperation(
              address.append(LOGIN_MODULE, CustomEjbAccessingLoginModule.class.getName()));
      loginModule2.get(CODE).set(CustomEjbAccessingLoginModule.class.getName());
      loginModule2.get(FLAG).set("required");

      loginModule.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true);
      loginModule2.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true);

      updates.add(loginModule);
      updates.add(loginModule2);

      applyUpdates(managementClient.getControllerClient(), Arrays.asList(compositeOp));
    }
  public static void excludeBadOps_7_1_x(LegacyKernelServicesInitializer initializer) {
    // deployment overlays don't exist in 7.1.x
    initializer.addOperationValidationExclude(
        ADD, PathAddress.pathAddress(PathElement.pathElement(DEPLOYMENT_OVERLAY)));

    initializer.addOperationValidationExclude(
        ADD,
        PathAddress.pathAddress(
            PathElement.pathElement(DEPLOYMENT_OVERLAY), PathElement.pathElement(CONTENT)));
    initializer.addOperationValidationExclude(
        ADD,
        PathAddress.pathAddress(
            PathElement.pathElement(SERVER_GROUP), PathElement.pathElement(DEPLOYMENT_OVERLAY)));

    // Socket binding group/socket-binding has problems if there are expressions in the
    // multicast-port
    initializer.addOperationValidationResolve(
        ADD,
        PathAddress.pathAddress(
            PathElement.pathElement(SOCKET_BINDING_GROUP),
            PathElement.pathElement(SOCKET_BINDING)));

    // Deployment operation validator thinks that content is required
    initializer.addOperationValidationExclude(
        ADD,
        PathAddress.pathAddress(
            PathElement.pathElement(SERVER_GROUP), PathElement.pathElement(DEPLOYMENT)));
  }
  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);
    }
  }
 private boolean checkHostServersStarted(DomainClient masterClient, String host) {
   try {
     ModelNode op =
         Util.createEmptyOperation(
             READ_CHILDREN_NAMES_OPERATION, PathAddress.pathAddress(HOST, host));
     op.get(CHILD_TYPE).set(SERVER);
     ModelNode ret = DomainTestUtils.executeForResult(op, masterClient);
     List<ModelNode> list = ret.asList();
     for (ModelNode entry : list) {
       String server = entry.asString();
       op =
           Util.createEmptyOperation(
               READ_ATTRIBUTE_OPERATION,
               PathAddress.pathAddress(HOST, host).append(SERVER, server));
       op.get(NAME).set("server-state");
       ModelNode state = DomainTestUtils.executeForResult(op, masterClient);
       if (SUCCESS.equals(state.get(OUTCOME).asString())) {
         return "running".equals(state.get(RESULT).asString());
       }
     }
     return false;
   } catch (Exception e) {
     return false;
   }
 }
 String getServerGroupName(final ModelNode operation) {
   final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
   if (address.size() == 0) {
     return null;
   }
   return address.getLastElement().getValue();
 }
 public void addStep(
     ModelNode operation,
     OperationStepHandler step,
     OperationContext.Stage stage,
     boolean addFirst)
     throws IllegalArgumentException {
   final PathAddress opAddress = PathAddress.pathAddress(operation.get(OP_ADDR));
   if (!expectedSteps.contains(opAddress) && failOnUnexpected) {
     if (opAddress.size() == 2) {
       // Ignore the add/removing running server add step done by ServerAddHandler and
       // ServerRemoveHandler
       if (opAddress.getElement(0).getKey().equals(HOST)
           && opAddress.getElement(1).getKey().equals(SERVER)
           && (operation.get(OP).asString().equals(ADD)
               || operation.get(OP).asString().equals(REMOVE))) {
         return;
       }
     }
     fail("Should not have added step for: " + opAddress);
   }
   expectedSteps.remove(opAddress);
   List<OperationAndHandler> stageList = addedSteps.get(stage);
   if (stageList == null) {
     stageList = new ArrayList<OperationAndHandler>();
     addedSteps.put(stage, stageList);
   }
   OperationAndHandler oah = new OperationAndHandler(operation, step);
   if (addFirst) {
     stageList.add(0, oah);
   } else {
     stageList.add(oah);
   }
 }
  @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);
  }
Пример #12
0
    /** {@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();
    }
Пример #13
0
 @Override
 protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
     throws OperationFailedException {
   final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
   final String name = address.getLastElement().getValue();
   ModClusterService.install(name, context.getServiceTarget(), model, context);
 }
 protected void describe(
     final Resource resource,
     final ModelNode address,
     ModelNode result,
     final ImmutableManagementResourceRegistration registration) {
   if (registration.isRemote()
       || registration.isRuntimeOnly()
       || resource.isProxy()
       || resource.isRuntime()) {
     return;
   }
   final Set<PathElement> children = registration.getChildAddresses(PathAddress.EMPTY_ADDRESS);
   result.add(createAddOperation(address, resource.getModel(), children));
   for (final PathElement element : children) {
     if (element.isMultiTarget()) {
       final String childType = element.getKey();
       for (final Resource.ResourceEntry entry : resource.getChildren(childType)) {
         final ImmutableManagementResourceRegistration childRegistration =
             registration.getSubModel(
                 PathAddress.pathAddress(PathElement.pathElement(childType, entry.getName())));
         final ModelNode childAddress = address.clone();
         childAddress.add(childType, entry.getName());
         describe(entry, childAddress, result, childRegistration);
       }
     } else {
       final Resource child = resource.getChild(element);
       final ImmutableManagementResourceRegistration childRegistration =
           registration.getSubModel(PathAddress.pathAddress(element));
       final ModelNode childAddress = address.clone();
       childAddress.add(element.getKey(), element.getValue());
       describe(child, childAddress, result, childRegistration);
     }
   }
 }
Пример #15
0
  @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"));
    }
  }
Пример #16
0
  @Override
  protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
      throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    final String name = address.getLastElement().getValue();
    final ServiceTarget serviceTarget = context.getServiceTarget();
    final ServiceName serviceName =
        MessagingServices.getActiveMQServiceName(
            PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));

    final ModelNode selectorNode = SELECTOR.resolveModelAttribute(context, model);
    final boolean durable = DURABLE.resolveModelAttribute(context, model).asBoolean();

    final String selector = selectorNode.isDefined() ? selectorNode.asString() : null;

    // Do not pass the JNDI bindings to ActiveMQ but install them directly instead so that the
    // dependencies from the BinderServices to the JMSQueueService are not broken
    Service<Queue> queueService =
        JMSQueueService.installService(
            name, serviceTarget, serviceName, selector, durable, new String[0]);

    final ModelNode entries =
        CommonAttributes.DESTINATION_ENTRIES.resolveModelAttribute(context, model);
    final ServiceName jmsQueueServiceName =
        JMSServices.getJmsQueueBaseServiceName(serviceName).append(name);
    final String[] jndiBindings = JMSServices.getJndiBindings(entries);
    for (String jndiBinding : jndiBindings) {
      // install a binder service which depends on the JMS queue service
      BinderServiceUtil.installBinderService(
          serviceTarget, jndiBinding, queueService, jmsQueueServiceName);
    }
  }
Пример #17
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();
    }
Пример #18
0
  @Test
  public void testParseSubsystem_1_0() throws Exception {
    String subsystemXml =
        "<subsystem xmlns=\"urn:jboss:domain:jacorb:1.0\">"
            + "    <orb name=\"JBoss\" print-version=\"off\">"
            + "        <connection retries=\"5\" retry-interval=\"500\" client-timeout=\"0\" server-timeout=\"0\"/>"
            + "        <naming root-context=\"JBoss/Naming/root\" export-corbaloc=\"on\"/>"
            + "    </orb>"
            + "    <poa monitoring=\"off\" queue-wait=\"on\" queue-min=\"10\" queue-max=\"100\">"
            + "        <request-processors pool-size=\"10\" max-threads=\"32\"/>"
            + "    </poa>"
            + "    <interop sun=\"on\" comet=\"off\" chunk-custom-rmi-valuetypes=\"on\"/>"
            + "    <security support-ssl=\"off\" use-domain-socket-factory=\"off\" use-domain-server-socket-factory=\"off\"/>"
            + "    <property key=\"a\" value=\"va\"/>"
            + "    <property key=\"b\" value=\"vb\"/>"
            + "    <initializers>security,transactions</initializers>"
            + "</subsystem>";

    List<ModelNode> operations = super.parse(subsystemXml);

    // check that we have the expected number of operations.
    Assert.assertEquals(1, operations.size());
    // check that each operation has the correct content.
    ModelNode addSubsystem = operations.get(0);
    Assert.assertEquals(ADD, addSubsystem.get(OP).asString());
    PathAddress addr = PathAddress.pathAddress(addSubsystem.get(OP_ADDR));
    Assert.assertEquals(1, addr.size());
    PathElement element = addr.getElement(0);
    Assert.assertEquals(SUBSYSTEM, element.getKey());
    Assert.assertEquals(JacORBExtension.SUBSYSTEM_NAME, element.getValue());
  }
 public void addResource(PathAddress relativeAddress, Resource toAdd) {
   Resource model = root;
   final Iterator<PathElement> i = relativeAddress.iterator();
   while (i.hasNext()) {
     final PathElement element = i.next();
     if (element.isMultiTarget()) {
       throw MESSAGES.cannotWriteTo("*");
     }
     if (!i.hasNext()) {
       if (model.hasChild(element)) {
         throw MESSAGES.duplicateResourceAddress(relativeAddress);
       } else {
         model.registerChild(element, toAdd);
         model = toAdd;
       }
     } else {
       model = model.getChild(element);
       if (model == null) {
         PathAddress ancestor = PathAddress.EMPTY_ADDRESS;
         for (PathElement pe : relativeAddress) {
           ancestor = ancestor.append(pe);
           if (element.equals(pe)) {
             break;
           }
         }
         throw MESSAGES.resourceNotFound(ancestor, relativeAddress);
       }
     }
   }
 }
Пример #20
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);
  }
  public static void createServerAddOperations(
      final List<ModelNode> addOps, final PathAddress protocolAddress, final ModelNode protocol) {
    addOps.add(createProtocolAddOperation(protocolAddress, protocol));

    final SyslogAuditLogHandler.Transport transport =
        SyslogAuditLogHandler.Transport.valueOf(
            protocolAddress.getLastElement().getValue().toUpperCase(Locale.ENGLISH));
    if (transport == SyslogAuditLogHandler.Transport.TLS) {
      if (protocol.hasDefined(AUTHENTICATION)) {
        final ModelNode auth = protocol.get(AUTHENTICATION);
        if (auth.hasDefined(TRUSTSTORE)) {
          addOps.add(
              createKeystoreAddOperation(
                  protocolAddress.append(AUTHENTICATION, TRUSTSTORE),
                  protocol.get(AUTHENTICATION, TRUSTSTORE)));
        }
        if (auth.hasDefined(CLIENT_CERT_STORE)) {
          addOps.add(
              createKeystoreAddOperation(
                  protocolAddress.append(AUTHENTICATION, CLIENT_CERT_STORE),
                  protocol.get(AUTHENTICATION, CLIENT_CERT_STORE)));
        }
      }
    }
  }
  /** Tests that the xml is parsed into the correct operations */
  @Test
  public void testParseSubsystem() throws Exception {
    // Parse the subsystem xml into operations
    List<ModelNode> operations = super.parse(getSubsystemXml());

    /*
    // print the operations
    System.out.println("List of operations");
    for (ModelNode op : operations) {
        System.out.println("operation = " + op.toString());
    }
    */

    // Check that we have the expected number of operations
    // one for each resource instance
    Assert.assertEquals(this.operations, operations.size());

    // Check that each operation has the correct content
    ModelNode addSubsystem = operations.get(0);
    Assert.assertEquals(ADD, addSubsystem.get(OP).asString());
    PathAddress addr = PathAddress.pathAddress(addSubsystem.get(OP_ADDR));
    Assert.assertEquals(1, addr.size());
    PathElement element = addr.getElement(0);
    Assert.assertEquals(SUBSYSTEM, element.getKey());
    Assert.assertEquals(getMainSubsystemName(), element.getValue());
  }
 @Test
 public void testConfigurationChanges() throws Exception {
   final ModelNode listConfigurationChanges =
       Util.createOperation(ConfigurationChangeResourceDefinition.OPERATION_NAME, ADDRESS);
   List<ModelNode> changes =
       getManagementClient().executeForResult(listConfigurationChanges).asList();
   assertThat(changes.size(), is(3));
   for (ModelNode change : changes) {
     assertThat(change.hasDefined(OPERATION_DATE), is(true));
     assertThat(change.hasDefined(USER_ID), is(false));
     assertThat(change.hasDefined(DOMAIN_UUID), is(false));
     assertThat(change.hasDefined(ACCESS_MECHANISM), is(true));
     assertThat(change.get(ACCESS_MECHANISM).asString(), is("NATIVE"));
     assertThat(change.hasDefined(REMOTE_ADDRESS), is(true));
     assertThat(change.get(OUTCOME).asString(), is(SUCCESS));
     assertThat(change.get(OPERATIONS).asList().size(), is(1));
   }
   ModelNode currentChange = changes.get(0);
   ModelNode currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
   assertThat(currentChangeOp.get(OP).asString(), is(REMOVE));
   assertThat(currentChangeOp.get(OP_ADDR).asString(), is(SYSTEM_PROPERTY_ADDRESS.toString()));
   currentChange = changes.get(1);
   currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
   assertThat(currentChangeOp.get(OP).asString(), is(UNDEFINE_ATTRIBUTE_OPERATION));
   assertThat(
       currentChangeOp.get(OP_ADDR).asString(),
       is(ALLOWED_ORIGINS_ADDRESS.toModelNode().asString()));
   currentChange = changes.get(2);
   currentChangeOp = currentChange.get(OPERATIONS).asList().get(0);
   assertThat(currentChangeOp.get(OP).asString(), is(ADD));
   assertThat(
       currentChangeOp.get(OP_ADDR).asString(),
       is(SYSTEM_PROPERTY_ADDRESS.toModelNode().asString()));
 }
  private void testTransformers(ModelTestControllerVersion controllerVersion) throws Exception {
    ModelVersion modelVersion = ModelVersion.create(1, 0, 0);
    KernelServicesBuilder builder = createKernelServicesBuilder(createAdditionalInitialization());

    builder
        .createLegacyKernelServicesBuilder(
            createAdditionalInitialization(), controllerVersion, modelVersion)
        .addMavenResourceURL("org.jboss.as:jboss-as-cmp:" + controllerVersion.getMavenGavVersion())
        .configureReverseControllerCheck(createAdditionalInitialization(), null);

    KernelServices mainServices = builder.build();
    Assert.assertTrue(mainServices.isSuccessfulBoot());
    Assert.assertTrue(mainServices.getLegacyServices(modelVersion).isSuccessfulBoot());

    ModelTestUtils.checkFailedTransformedBootOperations(
        mainServices,
        modelVersion,
        parse(getSubsystemXml()),
        new FailedOperationTransformationConfig()
            .addFailedAttribute(
                SUBSYSTEM_PATH.append(CmpSubsystemModel.UUID_KEY_GENERATOR_PATH),
                new FailedOperationTransformationConfig.NewAttributesConfig(
                    CMPSubsystemRootResourceDefinition.JNDI_NAME))
            .addFailedAttribute(
                SUBSYSTEM_PATH.append(CmpSubsystemModel.HILO_KEY_GENERATOR_PATH),
                new FailedOperationTransformationConfig.NewAttributesConfig(
                    CMPSubsystemRootResourceDefinition.JNDI_NAME)));
  }
 @Override
 public int compare(final PathAddress o1, final PathAddress o2) {
   final String key1 = o1.getLastElement().getKey();
   final String key2 = o2.getLastElement().getKey();
   int result = key1.compareTo(key2);
   if (result != EQUAL) {
     if (LoggingProfileOperations.isLoggingProfileAddress(o1)
         && !LoggingProfileOperations.isLoggingProfileAddress(o2)) {
       result = GREATER;
     } else if (!LoggingProfileOperations.isLoggingProfileAddress(o1)
         && LoggingProfileOperations.isLoggingProfileAddress(o2)) {
       result = LESS;
     } else if (LoggingProfileOperations.isLoggingProfileAddress(o1)
         && LoggingProfileOperations.isLoggingProfileAddress(o2)) {
       if (CommonAttributes.LOGGING_PROFILE.equals(key1)
           && !CommonAttributes.LOGGING_PROFILE.equals(key2)) {
         result = LESS;
       } else if (!CommonAttributes.LOGGING_PROFILE.equals(key1)
           && CommonAttributes.LOGGING_PROFILE.equals(key2)) {
         result = GREATER;
       } else {
         result = compare(key1, key2);
       }
     } else {
       result = compare(key1, key2);
     }
   }
   return result;
 }
 private void assertOperation(
     final ModelNode operation, final String operationName, final PathElement lastElement) {
   assertEquals(operationName, operation.get(OP).asString());
   final PathAddress addr = PathAddress.pathAddress(operation.get(OP_ADDR));
   final PathElement element = addr.getLastElement();
   assertEquals(lastElement.getKey(), element.getKey());
   assertEquals(lastElement.getValue(), element.getValue());
 }
 void println(String msg) {
   if (!outputPath) {
     outputPath = true;
     PathAddress relative = pathAddress.subAddress(rootAddress.size());
     System.out.println(
         "--- Problems for relative address to root " + formatAddressOneLine(relative) + ":");
   }
   System.out.println(msg);
 }
Пример #28
0
  @Override
  protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
      throws OperationFailedException {

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

    context.removeService(WSServices.CLIENT_CONFIG_SERVICE.append(name));
    context.reloadRequired();
  }
Пример #29
0
  public static PathAddress getParentAddressByKey(PathAddress address, String parentKey) {
    for (int i = address.size() - 1; i >= 0; i--) {
      PathElement pe = address.getElement(i);
      if (parentKey.equals(pe.getKey())) {
        return address.subAddress(0, i + 1);
      }
    }

    return null;
  }
 private void addCredential(
     PathAddress parent, KeycloakAdapterConfigService service, String key, String value) {
   PathAddress credAddr =
       PathAddress.pathAddress(parent, PathElement.pathElement("credential", key));
   ModelNode credOp = new ModelNode();
   credOp.get(ModelDescriptionConstants.OP_ADDR).set(credAddr.toModelNode());
   ModelNode credential = new ModelNode();
   credential.get("value").set(value);
   service.addCredential(credOp, credential);
 }