@Override
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    if (context.getType() == OperationContext.Type.SERVER) {
      context.addStep(
          new OperationStepHandler() {
            @Override
            public void execute(OperationContext context, ModelNode operation)
                throws OperationFailedException {
              ServiceController<?> controller =
                  context.getServiceRegistry(false).getService(ModClusterService.NAME);
              ModCluster modcluster = (ModCluster) controller.getValue();
              ROOT_LOGGER.debugf("add-proxy: %s", operation);

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

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

    context.completeStep();
  }
  public void execute(OperationContext context, ModelNode operation)
      throws OperationFailedException {
    Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
    final List<byte[]> removedHashes = DeploymentUtils.getDeploymentHash(resource);

    final ModelNode model = context.readModel(PathAddress.EMPTY_ADDRESS);

    context.removeResource(PathAddress.EMPTY_ADDRESS);

    if (context.getType() == OperationContext.Type.SERVER) {
      context.addStep(
          new OperationStepHandler() {
            public void execute(OperationContext context, ModelNode operation)
                throws OperationFailedException {
              String deploymentUnitName = null;

              boolean enabled = model.hasDefined(ENABLED) ? model.get(ENABLED).asBoolean() : true;
              if (enabled) {
                final ModelNode opAddr = operation.get(OP_ADDR);
                final PathAddress address = PathAddress.pathAddress(opAddr);
                final String name = address.getLastElement().getValue();
                deploymentUnitName =
                    model.hasDefined(RUNTIME_NAME) ? model.get(RUNTIME_NAME).asString() : name;
                final ServiceName deploymentUnitServiceName =
                    Services.deploymentUnitName(deploymentUnitName);
                context.removeService(deploymentUnitServiceName);
                context.removeService(deploymentUnitServiceName.append("contents"));
              }
              if (context.completeStep() == OperationContext.ResultAction.ROLLBACK) {
                recoverServices(context, operation, model);

                if (enabled && context.hasFailureDescription()) {
                  ServerLogger.ROOT_LOGGER.undeploymentRolledBack(
                      deploymentUnitName, context.getFailureDescription().asString());
                } else if (enabled) {
                  ServerLogger.ROOT_LOGGER.undeploymentRolledBackWithNoMessage(deploymentUnitName);
                }
              } else {
                if (enabled) {
                  ServerLogger.ROOT_LOGGER.deploymentUndeployed(deploymentUnitName);
                }
                if (standalone) {
                  for (byte[] hash : removedHashes) {
                    try {
                      contentRepository.removeContent(hash);
                    } catch (Exception e) {
                      // TODO
                      log.infof(e, "Exception occurred removing %s", hash);
                    }
                  }
                }
              }
            }
          },
          OperationContext.Stage.RUNTIME);
    }
    context.completeStep();
  }
  public void execute(OperationContext context, ModelNode operation) {

    final ModelNode model = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel();

    // On boot we invoke this op but we may not want to store a default value the model
    boolean persist = operation.get(PERSISTENT).asBoolean(true);
    if (persist) {
      model.get(ENABLED).set(true);
    } else if (model.hasDefined(ENABLED) && !model.get(ENABLED).asBoolean()) {
      // Just clear the "false" value that gets stored by default
      model.get(ENABLED).set(new ModelNode());
    }

    if (context.getType() == OperationContext.Type.SERVER) {

      context.addStep(
          new OperationStepHandler() {
            public void execute(OperationContext context, ModelNode operation)
                throws OperationFailedException {
              final ServiceTarget serviceTarget = context.getServiceTarget();
              final ServiceVerificationHandler verificationHandler =
                  new ServiceVerificationHandler();

              final ModelNode address = operation.require(OP_ADDR);
              final String dsName = PathAddress.pathAddress(address).getLastElement().getValue();
              final String jndiName = model.get(JNDINAME.getName()).asString();
              final ServiceRegistry registry = context.getServiceRegistry(true);

              final List<ServiceName> serviceNames = registry.getServiceNames();

              if (isXa()) {
                final ModifiableXaDataSource dataSourceConfig;
                try {
                  dataSourceConfig = xaFrom(context, model);
                } catch (ValidateException e) {
                  throw new OperationFailedException(
                      e,
                      new ModelNode()
                          .set(
                              MESSAGES.failedToCreate(
                                  "XaDataSource", operation, e.getLocalizedMessage())));
                }
                final ServiceName xaDataSourceConfigServiceName =
                    XADataSourceConfigService.SERVICE_NAME_BASE.append(dsName);
                final XADataSourceConfigService xaDataSourceConfigService =
                    new XADataSourceConfigService(dataSourceConfig);

                final ServiceBuilder<?> builder =
                    serviceTarget.addService(
                        xaDataSourceConfigServiceName, xaDataSourceConfigService);
                builder.addListener(verificationHandler);

                for (ServiceName name : serviceNames) {
                  if (xaDataSourceConfigServiceName
                      .append("xa-datasource-properties")
                      .isParentOf(name)) {
                    final ServiceController<?> xaConfigProperyController =
                        registry.getService(name);
                    XaDataSourcePropertiesService xaPropService =
                        (XaDataSourcePropertiesService) xaConfigProperyController.getService();

                    if (xaConfigProperyController != null) {
                      if (!ServiceController.State.UP.equals(
                          xaConfigProperyController.getState())) {
                        xaConfigProperyController.setMode(ServiceController.Mode.ACTIVE);
                        builder.addDependency(
                            name,
                            String.class,
                            xaDataSourceConfigService.getXaDataSourcePropertyInjector(
                                xaPropService.getName()));

                      } else {
                        throw new OperationFailedException(
                            new ModelNode()
                                .set(
                                    MESSAGES.serviceAlreadyStarted(
                                        "Data-source.xa-config-property", name)));
                      }
                    } else {
                      throw new OperationFailedException(
                          new ModelNode()
                              .set(
                                  MESSAGES.serviceNotAvailable(
                                      "Data-source.xa-config-property", name)));
                    }
                  }
                }
                builder.install();

              } else {

                final ModifiableDataSource dataSourceConfig;
                try {
                  dataSourceConfig = from(context, model);
                } catch (ValidateException e) {
                  e.printStackTrace();
                  throw new OperationFailedException(
                      e,
                      new ModelNode()
                          .set(
                              MESSAGES.failedToCreate(
                                  "DataSource", operation, e.getLocalizedMessage())));
                }
                final ServiceName dataSourceCongServiceName =
                    DataSourceConfigService.SERVICE_NAME_BASE.append(dsName);
                final DataSourceConfigService configService =
                    new DataSourceConfigService(dataSourceConfig);

                final ServiceBuilder<?> builder =
                    serviceTarget.addService(dataSourceCongServiceName, configService);
                builder.addListener(verificationHandler);

                for (ServiceName name : serviceNames) {
                  if (dataSourceCongServiceName.append("connetion-properties").isParentOf(name)) {
                    final ServiceController<?> dataSourceController = registry.getService(name);
                    ConnectionPropertiesService connPropService =
                        (ConnectionPropertiesService) dataSourceController.getService();

                    if (dataSourceController != null) {
                      if (!ServiceController.State.UP.equals(dataSourceController.getState())) {
                        dataSourceController.setMode(ServiceController.Mode.ACTIVE);
                        builder.addDependency(
                            name,
                            String.class,
                            configService.getConnectionPropertyInjector(connPropService.getName()));

                      } else {
                        throw new OperationFailedException(
                            new ModelNode()
                                .set(
                                    MESSAGES.serviceAlreadyStarted(
                                        "Data-source.connectionProperty", name)));
                      }
                    } else {
                      throw new OperationFailedException(
                          new ModelNode()
                              .set(
                                  MESSAGES.serviceNotAvailable(
                                      "Data-source.connectionProperty", name)));
                    }
                  }
                }
                builder.install();
              }
              context.completeStep();
            }
          },
          OperationContext.Stage.RUNTIME);

      context.addStep(
          new OperationStepHandler() {
            public void execute(OperationContext context, ModelNode operation)
                throws OperationFailedException {
              final ServiceTarget serviceTarget = context.getServiceTarget();
              final ServiceVerificationHandler verificationHandler =
                  new ServiceVerificationHandler();

              final ModelNode address = operation.require(OP_ADDR);
              final String dsName = PathAddress.pathAddress(address).getLastElement().getValue();
              final String jndiName = model.get(JNDINAME.getName()).asString();
              final ServiceRegistry registry = context.getServiceRegistry(true);

              final ServiceName dataSourceServiceName =
                  AbstractDataSourceService.SERVICE_NAME_BASE.append(dsName);

              final List<ServiceName> serviceNames = registry.getServiceNames();

              final ServiceController<?> dataSourceController =
                  registry.getService(dataSourceServiceName);

              if (dataSourceController != null) {
                if (!ServiceController.State.UP.equals(dataSourceController.getState())) {
                  dataSourceController.setMode(ServiceController.Mode.ACTIVE);
                } else {
                  throw new OperationFailedException(
                      new ModelNode().set(MESSAGES.serviceAlreadyStarted("Data-source", dsName)));
                }
              } else {
                throw new OperationFailedException(
                    new ModelNode().set(MESSAGES.serviceNotAvailable("Data-source", dsName)));
              }

              final DataSourceReferenceFactoryService referenceFactoryService =
                  new DataSourceReferenceFactoryService();
              final ServiceName referenceFactoryServiceName =
                  DataSourceReferenceFactoryService.SERVICE_NAME_BASE.append(dsName);
              final ServiceBuilder<?> referenceBuilder =
                  serviceTarget
                      .addService(referenceFactoryServiceName, referenceFactoryService)
                      .addDependency(
                          dataSourceServiceName,
                          javax.sql.DataSource.class,
                          referenceFactoryService.getDataSourceInjector());

              referenceBuilder.install();

              final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
              final BinderService binderService = new BinderService(bindInfo.getBindName());
              final ServiceBuilder<?> binderBuilder =
                  serviceTarget
                      .addService(bindInfo.getBinderServiceName(), binderService)
                      .addDependency(
                          referenceFactoryServiceName,
                          ManagedReferenceFactory.class,
                          binderService.getManagedObjectInjector())
                      .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:
                                  {
                                    SUBSYSTEM_DATASOURCES_LOGGER.boundDataSource(jndiName);
                                    break;
                                  }
                                case START_REQUESTED_to_DOWN:
                                  {
                                    SUBSYSTEM_DATASOURCES_LOGGER.unboundDataSource(jndiName);
                                    break;
                                  }
                                case REMOVING_to_REMOVED:
                                  {
                                    SUBSYSTEM_DATASOURCES_LOGGER.debugf(
                                        "Removed JDBC Data-source [%s]", jndiName);
                                    break;
                                  }
                              }
                            }
                          });
              binderBuilder
                  .setInitialMode(ServiceController.Mode.ACTIVE)
                  .addListener(verificationHandler);
              binderBuilder.install();

              context.completeStep();
            }
          },
          OperationContext.Stage.RUNTIME);
    }
    context.completeStep();
  }
 protected boolean requiresRuntime(OperationContext context) {
   return context.getType() == OperationContext.Type.SERVER;
 }