@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());
     }
   }
 }
  @org.junit.Ignore("This fails for some mysterious reason - but this isn't a critical test")
  @Test
  @BMRule(
      name = "Test remove rollback operation",
      targetClass = "org.jboss.as.clustering.jgroups.subsystem.StackRemoveHandler",
      targetMethod = "performRuntime",
      targetLocation = "AT EXIT",
      action = "traceln(\"Injecting rollback fault via Byteman\");$1.setRollbackOnly()")
  public void testProtocolStackRemoveRollback() throws Exception {

    KernelServices services = buildKernelServices();

    ModelNode operation =
        Operations.createCompositeOperation(addStackOp, addTransportOp, addProtocolOp);

    // add a protocol stack
    ModelNode result = services.executeOperation(operation);
    Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());

    // remove the protocol stack
    // the remove has OperationContext.setRollbackOnly() injected
    // and so is expected to fail
    result = services.executeOperation(removeStackOp);
    Assert.assertEquals(FAILED, result.get(OUTCOME).asString());

    // need to check that all services are correctly re-installed
    ServiceName channelFactoryServiceName =
        ProtocolStackServiceName.CHANNEL_FACTORY.getServiceName("maximal2");
    Assert.assertNotNull(
        "channel factory service not installed",
        services.getContainer().getService(channelFactoryServiceName));
  }
  /**
   * Test for https://issues.jboss.org/browse/WFLY-5290 where server/test hangs when using legacy
   * TRANSPORT alias:
   *
   * <p>Create a simple stack, then remove, re-add a different transport, remove twice expecting the
   * 2nd remove to fail. Tests both situations when stack in inferred from :add operation and when
   * its inferred from the existing resource.
   */
  @Test
  public void testLegacyTransportAliasSequence() throws Exception {

    KernelServices services = buildKernelServices();

    String stackName = "legacyStack";

    // add a sample stack to test legacy paths on
    ModelNode result =
        services.executeOperation(getProtocolStackAddOperationWithParameters(stackName));
    Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());

    // add a thread pool
    result = services.executeOperation(getLegacyThreadPoolAddOperation(stackName, "default"));
    Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());

    ModelNode op = getLegacyThreadPoolAddOperation(stackName, "default");
    op.get("operation").set("write-attribute");
    op.get("name").set("keepalive-time");
    op.get("value").set(999);
    result = services.executeOperation(op);
    Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());

    op = Operations.createReadResourceOperation(getSubsystemAddress());
    op.get(ModelDescriptionConstants.INCLUDE_ALIASES).set("true");
    op.get(ModelDescriptionConstants.RECURSIVE).set("true");
    result = services.executeOperation(op);
    Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());

    op =
        Util.createOperation(
            ModelDescriptionConstants.READ_RESOURCE_DESCRIPTION_OPERATION, getSubsystemAddress());
    op.get(ModelDescriptionConstants.INCLUDE_ALIASES).set("true");
    op.get(ModelDescriptionConstants.RECURSIVE).set("true");
    result = services.executeOperation(op);
    Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());

    result = services.executeOperation(getLegacyTransportRemoveOperation(stackName));
    Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());

    result = services.executeOperation(getLegacyTransportAddOperation(stackName, "TCP"));
    Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());

    result = services.executeOperation(getLegacyTransportRemoveOperation(stackName));
    Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());

    result = services.executeOperation(getLegacyTransportRemoveOperation(stackName));
    Assert.assertEquals(FAILED, result.get(OUTCOME).asString());
  }
  @Test
  public void testProtocolStackRemoveRemoveSequence() throws Exception {

    KernelServices services = buildKernelServices();

    ModelNode operation =
        Operations.createCompositeOperation(addStackOp, addTransportOp, addProtocolOp);

    // add a protocol stack
    ModelNode result = services.executeOperation(operation);
    Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());

    // remove the protocol stack
    result = services.executeOperation(removeStackOp);
    Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());

    // remove the protocol stack again
    result = services.executeOperation(removeStackOp);
    Assert.assertEquals(FAILED, result.get(OUTCOME).asString());
  }
예제 #5
0
  @Override
  protected void executeRuntimeStep(OperationContext context, ModelNode operation) {
    // Address is of the form: /subsystem=infinispan/cache-container=*/*-cache=*
    PathAddress address = context.getCurrentAddress();
    String containerName = address.getElement(address.size() - 2).getValue();
    String cacheName = address.getElement(address.size() - 1).getValue();
    String name = Operations.getAttributeName(operation);

    CacheMetric metric = CacheMetric.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) {
        context.getResult().set(metric.getValue(cache));
      }
    }
    context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER);
  }
  @Test
  public void testAliases() throws Exception {
    KernelServices services =
        this.createKernelServicesBuilder().setSubsystemXml(this.getSubsystemXml()).build();

    PathAddress address = getCacheContainerAddress("minimal");
    String alias = "alias0";

    ModelNode operation =
        Operations.createListAddOperation(
            address, CacheContainerResourceDefinition.Attribute.ALIASES, alias);
    ModelNode result = services.executeOperation(operation);
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertFalse(result.get(RESULT).isDefined());

    operation =
        Operations.createListGetOperation(
            address, CacheContainerResourceDefinition.Attribute.ALIASES, 0);
    result = services.executeOperation(operation);
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertEquals(new ModelNode(alias), result.get(RESULT));

    operation =
        Operations.createListRemoveOperation(
            address, CacheContainerResourceDefinition.Attribute.ALIASES, 0);
    result = services.executeOperation(operation);
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertFalse(result.get(RESULT).isDefined());

    operation =
        Operations.createListGetOperation(
            address, CacheContainerResourceDefinition.Attribute.ALIASES, 0);
    result = services.executeOperation(operation);
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertFalse(result.get(RESULT).isDefined());

    // Validate that aliases can still be added/removed via legacy operations
    operation = Util.createOperation("add-alias", address);
    operation.get(ModelDescriptionConstants.NAME).set(alias);
    result = services.executeOperation(operation);
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertFalse(result.get(RESULT).isDefined());

    operation =
        Operations.createListGetOperation(
            address, CacheContainerResourceDefinition.Attribute.ALIASES, 0);
    result = services.executeOperation(operation);
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    /* This currently fails due to WFCORE-626, requires wildfly-core-1.0.0.Beta4
    Assert.assertEquals(new ModelNode(alias), result.get(RESULT));
    */
    operation = Util.createOperation("remove-alias", address);
    operation.get(ModelDescriptionConstants.NAME).set(alias);
    result = services.executeOperation(operation);
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertFalse(result.get(RESULT).isDefined());

    operation =
        Operations.createListGetOperation(
            address, CacheContainerResourceDefinition.Attribute.ALIASES, 0);
    result = services.executeOperation(operation);
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertFalse(result.get(RESULT).isDefined());
  }
  @SuppressWarnings("deprecation")
  @Test
  public void testStoreProperties() throws Exception {
    KernelServices services =
        this.createKernelServicesBuilder().setSubsystemXml(this.getSubsystemXml()).build();

    PathAddress address =
        getRemoteCacheStoreAddress(
            "maximal", InvalidationCacheResourceDefinition.WILDCARD_PATH.getKey(), "invalid");
    String key = "infinispan.client.hotrod.ping_on_startup";
    String value = "true";

    ModelNode operation =
        Operations.createMapPutOperation(
            address, StoreResourceDefinition.Attribute.PROPERTIES, key, value);
    ModelNode result = services.executeOperation(operation);
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertFalse(result.get(RESULT).isDefined());

    operation =
        Operations.createMapGetOperation(
            address, StoreResourceDefinition.Attribute.PROPERTIES, key);
    result = services.executeOperation(operation);
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertEquals(value, result.get(RESULT).asString());

    operation =
        Operations.createMapRemoveOperation(
            address, StoreResourceDefinition.Attribute.PROPERTIES, key);
    result = services.executeOperation(operation);
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertFalse(result.get(RESULT).isDefined());

    operation =
        Operations.createMapGetOperation(
            address, StoreResourceDefinition.Attribute.PROPERTIES, key);
    result = services.executeOperation(operation);
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertFalse(result.get(RESULT).isDefined());

    // Validate that properties can still be added/removed/updated via child property resources
    PathAddress propertyAddress = address.append(StorePropertyResourceDefinition.pathElement(key));
    operation =
        Operations.createAddOperation(
            propertyAddress,
            Collections.<Attribute, ModelNode>singletonMap(
                new SimpleAttribute(StorePropertyResourceDefinition.VALUE), new ModelNode(value)));
    result = services.executeOperation(operation);
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertFalse(result.get(RESULT).isDefined());

    operation =
        Operations.createMapGetOperation(
            address, StoreResourceDefinition.Attribute.PROPERTIES, key);
    result = services.executeOperation(operation);
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertEquals(value, result.get(RESULT).asString());

    value = "false";
    operation =
        Operations.createWriteAttributeOperation(
            propertyAddress,
            new SimpleAttribute(StorePropertyResourceDefinition.VALUE),
            new ModelNode(value));
    result = services.executeOperation(operation);
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertFalse(result.get(RESULT).isDefined());

    operation =
        Operations.createMapGetOperation(
            address, StoreResourceDefinition.Attribute.PROPERTIES, key);
    result = services.executeOperation(operation);
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertEquals(value, result.get(RESULT).asString());

    operation =
        Operations.createReadAttributeOperation(
            propertyAddress, new SimpleAttribute(StorePropertyResourceDefinition.VALUE));
    result = services.executeOperation(operation);
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertEquals(value, result.get(RESULT).asString());

    operation = Util.createRemoveOperation(propertyAddress);
    result = services.executeOperation(operation);
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertFalse(result.get(RESULT).isDefined());

    operation =
        Operations.createMapGetOperation(
            address, StoreResourceDefinition.Attribute.PROPERTIES, key);
    result = services.executeOperation(operation);
    Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString());
    Assert.assertFalse(result.get(RESULT).isDefined());
  }