private void addLocalService(
      OperationContext context,
      ModelNode local,
      String realmName,
      ServiceTarget serviceTarget,
      List<ServiceController<?>> newControllers,
      ServiceBuilder<?> realmBuilder,
      Injector<CallbackHandlerService> injector)
      throws OperationFailedException {
    ServiceName localServiceName =
        LocalCallbackHandlerService.ServiceUtil.createServiceName(realmName);

    ModelNode node =
        LocalAuthenticationResourceDefinition.DEFAULT_USER.resolveModelAttribute(context, local);
    String defaultUser = node.isDefined() ? node.asString() : null;
    node =
        LocalAuthenticationResourceDefinition.ALLOWED_USERS.resolveModelAttribute(context, local);
    String allowedUsers = node.isDefined() ? node.asString() : null;
    LocalCallbackHandlerService localCallbackHandler =
        new LocalCallbackHandlerService(defaultUser, allowedUsers);

    ServiceBuilder<?> jaasBuilder =
        serviceTarget.addService(localServiceName, localCallbackHandler);
    final ServiceController<?> serviceController = jaasBuilder.setInitialMode(ON_DEMAND).install();
    if (newControllers != null) {
      newControllers.add(serviceController);
    }

    CallbackHandlerService.ServiceUtil.addDependency(
        realmBuilder, injector, localServiceName, false);
  }
Esempio n. 2
0
    private void setInputComponentValue() {
      ModelNode valueToSet = defaultValue;
      if (value != null) valueToSet = value;
      if (valueToSet == null) return;

      if (valueComponent instanceof JLabel) {
        ((JLabel) valueComponent).setText(valueToSet.asString());
      }

      if (valueComponent instanceof ListEditor) {
        ((ListEditor) valueComponent).setValue(valueToSet);
      }

      if (!valueToSet.isDefined()) return;

      if (valueComponent instanceof JTextComponent) {
        ((JTextComponent) valueComponent).setText(valueToSet.asString());
      }

      if (valueComponent instanceof JCheckBox) {
        ((JCheckBox) valueComponent).setSelected(valueToSet.asBoolean());
      }

      if (valueComponent instanceof JComboBox) {
        ((JComboBox) valueComponent).setSelectedItem(valueToSet.asString());
      }

      if (valueComponent instanceof BrowsePanel) {
        ((BrowsePanel) valueComponent).setText(valueToSet.asString());
      }
    }
Esempio n. 3
0
 @Override
 protected boolean rejectAttribute(
     PathAddress address,
     String attributeName,
     ModelNode attributeValue,
     TransformationContext context) {
   if (attributeValue.isDefined()) {
     for (ModelNode node : attributeValue.asList()) {
       if (node.hasDefined(ANNOTATIONS)) {
         ModelNode annotations = node.get(ANNOTATIONS);
         if (EXPRESSION_PATTERN.matcher(annotations.asString()).matches()
             || annotations.asBoolean()) {
           return true;
         }
       }
       if (node.hasDefined(SERVICES)) {
         ModelNode services = node.get(SERVICES);
         if (EXPRESSION_PATTERN.matcher(services.asString()).matches()
             || !services.asBoolean()) {
           return true;
         }
       }
       if (node.hasDefined(META_INF)) {
         ModelNode metaInf = node.get(META_INF);
         if (EXPRESSION_PATTERN.matcher(metaInf.asString()).matches() || metaInf.asBoolean()) {
           return true;
         }
       }
     }
   }
   return false;
 }
  private void addLdapService(
      OperationContext context,
      ModelNode ldap,
      String realmName,
      ServiceTarget serviceTarget,
      List<ServiceController<?>> newControllers,
      ServiceBuilder<?> realmBuilder,
      Injector<CallbackHandlerService> injector,
      boolean shareConnection)
      throws OperationFailedException {
    ServiceName ldapServiceName = UserLdapCallbackHandler.ServiceUtil.createServiceName(realmName);

    final String baseDn =
        LdapAuthenticationResourceDefinition.BASE_DN
            .resolveModelAttribute(context, ldap)
            .asString();
    ModelNode node =
        LdapAuthenticationResourceDefinition.USERNAME_FILTER.resolveModelAttribute(context, ldap);
    final String usernameAttribute = node.isDefined() ? node.asString() : null;
    node =
        LdapAuthenticationResourceDefinition.ADVANCED_FILTER.resolveModelAttribute(context, ldap);
    final String advancedFilter = node.isDefined() ? node.asString() : null;
    final boolean recursive =
        LdapAuthenticationResourceDefinition.RECURSIVE
            .resolveModelAttribute(context, ldap)
            .asBoolean();
    final boolean allowEmptyPasswords =
        LdapAuthenticationResourceDefinition.ALLOW_EMPTY_PASSWORDS
            .resolveModelAttribute(context, ldap)
            .asBoolean();
    final String userDn =
        LdapAuthenticationResourceDefinition.USER_DN
            .resolveModelAttribute(context, ldap)
            .asString();
    UserLdapCallbackHandler ldapCallbackHandler =
        new UserLdapCallbackHandler(
            baseDn,
            usernameAttribute,
            advancedFilter,
            recursive,
            userDn,
            allowEmptyPasswords,
            shareConnection);

    ServiceBuilder<?> ldapBuilder = serviceTarget.addService(ldapServiceName, ldapCallbackHandler);
    String connectionManager =
        LdapAuthenticationResourceDefinition.CONNECTION
            .resolveModelAttribute(context, ldap)
            .asString();
    LdapConnectionManagerService.ServiceUtil.addDependency(
        ldapBuilder, ldapCallbackHandler.getConnectionManagerInjector(), connectionManager, false);

    final ServiceController<?> serviceController = ldapBuilder.setInitialMode(ON_DEMAND).install();
    if (newControllers != null) {
      newControllers.add(serviceController);
    }

    CallbackHandlerService.ServiceUtil.addDependency(
        realmBuilder, injector, ldapServiceName, false);
  }
  @SuppressWarnings({"unchecked", "rawtypes"})
  private void configureCredentialHandlers(
      OperationContext context,
      ModelNode identityStore,
      IdentityStoreConfigurationBuilder<?, ?> storeConfig)
      throws OperationFailedException {
    if (identityStore.hasDefined(IDENTITY_STORE_CREDENTIAL_HANDLER.getName())) {
      for (Property credentialHandler :
          identityStore.get(IDENTITY_STORE_CREDENTIAL_HANDLER.getName()).asPropertyList()) {
        ModelNode classNameNode =
            CredentialHandlerResourceDefinition.CLASS_NAME.resolveModelAttribute(
                context, credentialHandler.getValue());
        ModelNode codeNode =
            CredentialHandlerResourceDefinition.CODE.resolveModelAttribute(
                context, credentialHandler.getValue());
        ModelNode moduleNode =
            CredentialHandlerResourceDefinition.MODULE.resolveModelAttribute(
                context, credentialHandler.getValue());
        String typeName;

        if (classNameNode.isDefined()) {
          typeName = classNameNode.asString();
        } else if (codeNode.isDefined()) {
          typeName = CredentialTypeEnum.forType(codeNode.asString());
        } else {
          throw ROOT_LOGGER.typeNotProvided(IDENTITY_STORE_CREDENTIAL_HANDLER.getName());
        }

        storeConfig.addCredentialHandler(this.<CredentialHandler>loadClass(moduleNode, typeName));
      }
    }
  }
  private void configureSupportedTypes(
      OperationContext context,
      ModelNode identityStore,
      IdentityStoreConfigurationBuilder storeConfig)
      throws OperationFailedException {
    boolean hasSupportedType = identityStore.hasDefined(SUPPORTED_TYPES.getName());

    if (hasSupportedType) {
      ModelNode featuresSetNode =
          identityStore.get(SUPPORTED_TYPES.getName()).asProperty().getValue();
      ModelNode supportsAllNode =
          SupportedTypesResourceDefinition.SUPPORTS_ALL.resolveModelAttribute(
              context, featuresSetNode);

      if (supportsAllNode.asBoolean()) {
        storeConfig.supportAllFeatures();
      }

      hasSupportedType = supportsAllNode.asBoolean();

      if (featuresSetNode.hasDefined(SUPPORTED_TYPE.getName())) {
        for (Property supportedTypeNode :
            featuresSetNode.get(SUPPORTED_TYPE.getName()).asPropertyList()) {
          ModelNode supportedType = supportedTypeNode.getValue();
          ModelNode classNameNode =
              SupportedTypeResourceDefinition.CLASS_NAME.resolveModelAttribute(
                  context, supportedType);
          ModelNode codeNode =
              SupportedTypeResourceDefinition.CODE.resolveModelAttribute(context, supportedType);
          String typeName;

          if (classNameNode.isDefined()) {
            typeName = classNameNode.asString();
          } else if (codeNode.isDefined()) {
            typeName = AttributedTypeEnum.forType(codeNode.asString());
          } else {
            throw ROOT_LOGGER.typeNotProvided(SUPPORTED_TYPE.getName());
          }

          ModelNode moduleNode =
              SupportedTypeResourceDefinition.MODULE.resolveModelAttribute(context, supportedType);
          Class<? extends AttributedType> attributedTypeClass = loadClass(moduleNode, typeName);

          if (Relationship.class.isAssignableFrom(attributedTypeClass)) {
            storeConfig.supportGlobalRelationship(
                (Class<? extends Relationship>) attributedTypeClass);
          } else {
            storeConfig.supportType(attributedTypeClass);
          }

          hasSupportedType = true;
        }
      }
    }

    if (!hasSupportedType) {
      throw ROOT_LOGGER.idmNoSupportedTypesDefined();
    }
  }
 @Override
 protected void validateReferencedNewValueExisits(OperationContext context, ModelNode value)
     throws OperationFailedException {
   final Resource root = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS, false);
   // Don't do this on boot since the domain model is not populated yet
   if (!context.isBooting()
       && root.getChild(PathElement.pathElement(SERVER_GROUP, value.asString())) == null) {
     throw HostControllerMessages.MESSAGES.noServerGroupCalled(value.asString());
   }
 }
  /**
   * Compares two models to make sure that they are the same
   *
   * @param node1 the first model
   * @param node2 the second model
   * @throws AssertionFailedError if the models were not the same
   */
  protected void compare(ModelNode node1, ModelNode node2) {
    Assert.assertEquals(getCompareStackAsString() + " types", node1.getType(), node2.getType());
    if (node1.getType() == ModelType.OBJECT) {
      final Set<String> keys1 = node1.keys();
      final Set<String> keys2 = node2.keys();
      Assert.assertEquals(node1 + "\n" + node2, keys1.size(), keys2.size());

      for (String key : keys1) {
        final ModelNode child1 = node1.get(key);
        Assert.assertTrue("Missing: " + key + "\n" + node1 + "\n" + node2, node2.has(key));
        final ModelNode child2 = node2.get(key);
        if (child1.isDefined()) {
          Assert.assertTrue(child1.toString(), child2.isDefined());
          stack.get().push(key + "/");
          compare(child1, child2);
          stack.get().pop();
        } else {
          Assert.assertFalse(child2.asString(), child2.isDefined());
        }
      }
    } else if (node1.getType() == ModelType.LIST) {
      List<ModelNode> list1 = node1.asList();
      List<ModelNode> list2 = node2.asList();
      Assert.assertEquals(list1 + "\n" + list2, list1.size(), list2.size());

      for (int i = 0; i < list1.size(); i++) {
        stack.get().push(i + "/");
        compare(list1.get(i), list2.get(i));
        stack.get().pop();
      }

    } else if (node1.getType() == ModelType.PROPERTY) {
      Property prop1 = node1.asProperty();
      Property prop2 = node2.asProperty();
      Assert.assertEquals(prop1 + "\n" + prop2, prop1.getName(), prop2.getName());
      stack.get().push(prop1.getName() + "/");
      compare(prop1.getValue(), prop2.getValue());
      stack.get().pop();

    } else {
      try {
        Assert.assertEquals(
            getCompareStackAsString()
                + "\n\""
                + node1.asString()
                + "\"\n\""
                + node2.asString()
                + "\"\n-----",
            node2.asString().trim(),
            node1.asString().trim());
      } catch (AssertionFailedError error) {
        throw error;
      }
    }
  }
  private void writeSequencing(XMLExtendedStreamWriter writer, ModelNode repository)
      throws XMLStreamException {
    if (has(repository, ModelKeys.SEQUENCER)) {
      writer.writeStartElement(Element.SEQUENCERS.getLocalName());
      if (repository.hasDefined(ModelKeys.SEQUENCERS_THREAD_POOL_NAME)) {
        writer.writeAttribute(
            Attribute.THREAD_POOL_NAME.getLocalName(),
            repository.get(ModelKeys.SEQUENCERS_THREAD_POOL_NAME).asString());
      }
      if (repository.hasDefined(ModelKeys.SEQUENCERS_MAX_POOL_SIZE)) {
        writer.writeAttribute(
            Attribute.MAX_POOL_SIZE.getLocalName(),
            repository.get(ModelKeys.SEQUENCERS_MAX_POOL_SIZE).asString());
      }

      ModelNode sequencerNode = repository.get(ModelKeys.SEQUENCER);

      for (Property sequencer : sequencerNode.asPropertyList()) {
        writer.writeStartElement(Element.SEQUENCER.getLocalName());
        writer.writeAttribute(Attribute.NAME.getLocalName(), sequencer.getName());
        ModelNode prop = sequencer.getValue();
        ModelAttributes.SEQUENCER_CLASSNAME.marshallAsAttribute(prop, writer);
        ModelAttributes.MODULE.marshallAsAttribute(prop, writer);

        // Write out the extra properties ...
        if (has(prop, ModelKeys.PROPERTIES)) {
          ModelNode properties = prop.get(ModelKeys.PROPERTIES);
          for (Property property : properties.asPropertyList()) {
            writer.writeAttribute(property.getName(), property.getValue().asString());
          }
        }
        if (has(prop, ModelKeys.PATH_EXPRESSIONS)) {
          List<ModelNode> pathExpressions = prop.get(ModelKeys.PATH_EXPRESSIONS).asList();
          switch (pathExpressions.size()) {
            case 0:
              break;
            case 1:
              ModelNode pathExpression = pathExpressions.iterator().next();
              writer.writeAttribute(
                  Attribute.PATH_EXPRESSION.getLocalName(), pathExpression.asString());
              break;
            default:
              for (ModelNode pathExpr : pathExpressions) {
                writer.writeStartElement(Element.PATH_EXPRESSION.getLocalName());
                writer.writeCharacters(pathExpr.asString());
                writer.writeEndElement();
              }
          }
        }
        writer.writeEndElement();
      }
      writer.writeEndElement();
    }
  }
 /**
  * Remove all deployments from the model.
  *
  * @throws IOException
  */
 private void cleanDeployments() throws IOException {
   List<ModelNode> deploymentList = getDeploymentList(OTHER_SERVER_GROUP_ADDRESS);
   for (ModelNode deployment : deploymentList) {
     removeDeployment(deployment.asString(), OTHER_SERVER_GROUP_ADDRESS);
   }
   deploymentList = getDeploymentList(MAIN_SERVER_GROUP_ADDRESS);
   for (ModelNode deployment : deploymentList) {
     removeDeployment(deployment.asString(), MAIN_SERVER_GROUP_ADDRESS);
   }
   deploymentList = getDeploymentList(PathAddress.EMPTY_ADDRESS);
   for (ModelNode deployment : deploymentList) {
     removeDeployment(deployment.asString(), PathAddress.EMPTY_ADDRESS);
   }
 }
 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;
   }
 }
 private void writeFailedMarker(final File deploymentFile, final ModelNode failureDescription) {
   final File failedMarker =
       new File(deploymentFile.getParent(), deploymentFile.getName() + FAILED_DEPLOY);
   final File deployMarker =
       new File(deploymentFile.getParent(), deploymentFile.getName() + DO_DEPLOY);
   if (deployMarker.exists() && !deployMarker.delete()) {
     log.warnf("Unable to remove marker file %s", deployMarker);
   }
   final File deployedMarker =
       new File(deploymentFile.getParent(), deploymentFile.getName() + DEPLOYED);
   if (deployedMarker.exists() && !deployedMarker.delete()) {
     log.warnf("Unable to remove marker file %s", deployedMarker);
   }
   FileOutputStream fos = null;
   try {
     failedMarker.createNewFile();
     fos = new FileOutputStream(failedMarker);
     fos.write(failureDescription.asString().getBytes());
   } catch (IOException io) {
     log.errorf(
         io,
         "Caught exception writing deployment failed marker file %s",
         failedMarker.getAbsolutePath());
   } finally {
     safeClose(fos);
   }
 }
Esempio n. 13
0
    public String getValueAsString() {
      if (valueComponent instanceof JLabel) {
        return ((JLabel) valueComponent).getText();
      }

      if (valueComponent instanceof JTextComponent) {
        return ((JTextComponent) valueComponent).getText();
      }

      if (valueComponent instanceof AbstractButton) {
        return Boolean.toString(((AbstractButton) valueComponent).isSelected());
      }

      if (valueComponent instanceof JComboBox) {
        return ((JComboBox) valueComponent).getSelectedItem().toString();
      }

      if (valueComponent instanceof ListEditor) {
        ModelNode list = ((ListEditor) valueComponent).getValue();
        if (list.isDefined()) return list.asString();
        return "";
      }

      if (valueComponent instanceof JLabel) {
        return ((JLabel) valueComponent).getText();
      }

      if (valueComponent instanceof BrowsePanel) {
        return ((BrowsePanel) valueComponent).getText();
      }

      return null;
    }
  private void addSecretService(
      OperationContext context,
      ModelNode secret,
      String realmName,
      ServiceTarget serviceTarget,
      List<ServiceController<?>> newControllers,
      ServiceBuilder<?> realmBuilder,
      Injector<CallbackHandlerFactory> injector)
      throws OperationFailedException {
    ServiceName secretServiceName = SecretIdentityService.ServiceUtil.createServiceName(realmName);

    ModelNode resolvedValueNode =
        SecretServerIdentityResourceDefinition.VALUE.resolveModelAttribute(context, secret);
    boolean base64 =
        secret.get(SecretServerIdentityResourceDefinition.VALUE.getName()).getType()
            != ModelType.EXPRESSION;

    SecretIdentityService sis = new SecretIdentityService(resolvedValueNode.asString(), base64);
    final ServiceController<CallbackHandlerFactory> serviceController =
        serviceTarget.addService(secretServiceName, sis).setInitialMode(ON_DEMAND).install();
    if (newControllers != null) {
      newControllers.add(serviceController);
    }

    CallbackHandlerFactory.ServiceUtil.addDependency(
        realmBuilder, injector, secretServiceName, false);
  }
 private static String takeSnapshot(ModelControllerClient client) throws Exception {
   ModelNode operation = new ModelNode();
   operation.get(OP).set("take-snapshot");
   ModelNode result = execute(client, operation);
   String snapshot = result.asString();
   return snapshot;
 }
Esempio n. 16
0
  private List<CommonAdminObject> buildAdminObjects(ModelNode parentNode) {
    List<CommonAdminObject> adminObjets = new ArrayList<CommonAdminObject>();
    if (parentNode.hasDefined(ADMIN_OBJECTS)) {
      for (ModelNode adminObject : parentNode.get(ADMIN_OBJECTS).asList()) {
        Map<String, String> configProperties = null;
        if (adminObject.hasDefined(CONFIG_PROPERTIES)) {
          configProperties =
              new HashMap<String, String>(adminObject.get(CONFIG_PROPERTIES).asList().size());
          for (ModelNode property : adminObject.get(CONFIG_PROPERTIES).asList()) {
            configProperties.put(property.asProperty().getName(), property.asString());
          }
        }
        String className = getStringIfSetOrGetDefault(adminObject, CLASS_NAME, null);
        String jndiName = getStringIfSetOrGetDefault(adminObject, JNDI_NAME, null);
        String poolName = getStringIfSetOrGetDefault(adminObject, POOL_NAME, null);
        boolean enabled = getBooleanIfSetOrGetDefault(adminObject, ENABLED, false);
        boolean useJavaContext = getBooleanIfSetOrGetDefault(adminObject, USE_JAVA_CONTEXT, false);

        CommonAdminObject adminObjet =
            new CommonAdminObjectImpl(
                configProperties, className, jndiName, poolName, enabled, useJavaContext);

        adminObjets.add(adminObjet);
      }
    }
    return adminObjets;
  }
Esempio n. 17
0
  static BroadcastGroupConfiguration createBroadcastGroupConfiguration(
      final OperationContext context,
      final Set<String> connectors,
      final String name,
      final ModelNode model)
      throws OperationFailedException {

    final long broadcastPeriod =
        BroadcastGroupDefinition.BROADCAST_PERIOD.resolveModelAttribute(context, model).asLong();
    final List<String> connectorRefs = new ArrayList<String>();
    if (model.hasDefined(CommonAttributes.CONNECTORS)) {
      for (ModelNode ref : model.get(CommonAttributes.CONNECTORS).asList()) {
        final String refName = ref.asString();
        if (!connectors.contains(refName)) {
          throw MessagingLogger.ROOT_LOGGER.wrongConnectorRefInBroadCastGroup(
              name, refName, connectors);
        }
        connectorRefs.add(refName);
      }
    }

    return new BroadcastGroupConfiguration()
        .setName(name)
        .setBroadcastPeriod(broadcastPeriod)
        .setConnectorInfos(connectorRefs);
  }
Esempio n. 18
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);
  }
  @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();
  }
  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();
    }
  }
  private Avail getAvailFromResponse(final ModelNode response, final AvailDMRTask task) {
    Avail avail;
    final ModelNode result = JBossASClient.getResults(response);
    final ModelNode valueNode = (task.getSubref() == null) ? result : result.get(task.getSubref());
    String value = null;
    if (valueNode.getType() != ModelType.UNDEFINED) {
      value = valueNode.asString();
    }
    if (value == null) {
      value = "";
    }

    String upRegex = task.getUpRegex();
    if (upRegex == null) {
      try {
        Integer valueAsNumber = new Integer(value);
        avail = (valueAsNumber.intValue() == 0) ? Avail.DOWN : Avail.UP;
      } catch (Exception e) {
        avail = (value.matches("(?i)(UP|OK)")) ? Avail.UP : Avail.DOWN;
      }
    } else {
      avail = (value.matches(upRegex)) ? Avail.UP : Avail.DOWN;
    }
    return avail;
  }
Esempio n. 22
0
 static Collection<SaslQop> asQopSet(final ModelNode node) {
   final Set<SaslQop> set = new HashSet<SaslQop>();
   for (final ModelNode element : node.asList()) {
     set.add(SaslQop.valueOf(element.asString()));
   }
   return set;
 }
  private Map<ServerIdentity, ControlledProcessState.State> getServerStatuses() {

    Map<ServerIdentity, ControlledProcessState.State> result =
        new HashMap<ServerIdentity, ControlledProcessState.State>();
    ModelNode op = new ModelNode();
    op.get("operation").set("read-children-names");
    op.get("child-type").set("server-config");
    op.get("address").add("host", configuration.getHostName());
    ModelNode opResult = executeForResult(new OperationBuilder(op).build());
    Set<String> servers = new HashSet<String>();
    for (ModelNode server : opResult.asList()) {
      servers.add(server.asString());
    }
    for (String server : servers) {
      ModelNode address = new ModelNode();
      address.add("host", configuration.getHostName());
      address.add("server-config", server);
      String group = readAttribute("group", address).asString();
      if (!readAttribute("auto-start", address).asBoolean()) continue;

      address = new ModelNode();
      address.add("host", configuration.getHostName());
      address.add("server", server);

      ControlledProcessState.State status =
          Enum.valueOf(
              ControlledProcessState.State.class,
              readAttribute("server-state", address).asString().toUpperCase(Locale.ENGLISH));
      ServerIdentity id = new ServerIdentity(configuration.getHostName(), group, server);
      result.put(id, status);
    }

    return result;
  }
Esempio n. 24
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);
  }
Esempio n. 25
0
 static Collection<String> asStringSet(final ModelNode node) {
   final Set<String> set = new HashSet<String>();
   for (final ModelNode element : node.asList()) {
     set.add(element.asString());
   }
   return set;
 }
Esempio n. 26
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);
    }
  }
Esempio n. 27
0
 public static ModelNode checkOperationResult(
     ModelNode operation, ModelNode result, Outcome expectedOutcome) {
   String outcome = result.get(OUTCOME).asString();
   switch (expectedOutcome) {
     case SUCCESS:
       if (!SUCCESS.equals(outcome)) {
         System.out.println("Failed: " + operation);
         System.out.print("Result: " + result);
         fail(result.get(FAILURE_DESCRIPTION).asString());
       }
       break;
     case UNAUTHORIZED:
       {
         if (!FAILED.equals(outcome)) {
           fail("Didn't fail: " + result.asString());
         }
         if (!result.get(FAILURE_DESCRIPTION).asString().contains("13456")
             && !result.asString().contains("11360")
             && !result.asString().contains("11361")
             && !result.asString().contains("11362")
             && !result.asString().contains("11363")) {
           fail("Incorrect failure type: " + result.asString());
         }
         break;
       }
     case HIDDEN:
       {
         if (!FAILED.equals(outcome)) {
           fail("Didn't fail: " + result.asString());
         }
         String failureDesc = result.get(FAILURE_DESCRIPTION).asString();
         if (!failureDesc.contains("14807")
             && !failureDesc.contains("14883")
             && !failureDesc.contains("11340")) {
           fail("Incorrect failure type: " + result.asString());
         }
         break;
       }
     case FAILED:
       {
         if (!FAILED.equals(outcome)) {
           fail("Didn't fail: " + result.asString());
         }
         String failureDesc = result.get(FAILURE_DESCRIPTION).asString();
         if (failureDesc.contains("14807")
             || failureDesc.contains("14883")
             || failureDesc.contains("13456")
             || failureDesc.contains("11340")) {
           fail("Incorrect failure type: " + result.asString());
         }
         break;
       }
     default:
       throw new IllegalStateException();
   }
   return result;
 }
 private static ModelNode executeTransformOperation(
     final KernelServices kernelServices, final ModelVersion modelVersion, final ModelNode op)
     throws OperationFailedException {
   TransformedOperation transformedOp = kernelServices.transformOperation(modelVersion, op);
   ModelNode result = kernelServices.executeOperation(modelVersion, transformedOp);
   Assert.assertTrue(result.asString(), Operations.successful(result));
   return result;
 }
Esempio n. 29
0
 private void parseCustomNodeTypes(ModelNode model, EditableDocument configDoc) {
   if (model.hasDefined(ModelKeys.NODE_TYPES)) {
     EditableArray nodeTypesArray = configDoc.getOrCreateArray(FieldName.NODE_TYPES);
     for (ModelNode nodeType : model.get(ModelKeys.NODE_TYPES).asList()) {
       nodeTypesArray.add(nodeType.asString());
     }
   }
 }
Esempio n. 30
0
 public final List<String> stringListValue() {
   List<ModelNode> listValue = listValue();
   List<String> result = new ArrayList<String>(listValue.size());
   for (ModelNode value : listValue) {
     result.add(value.asString());
   }
   return Collections.unmodifiableList(result);
 }