private ManagedServerBootCmdFactory createBootFactory(
     final String serverName, final ModelNode domainModel) {
   final String hostControllerName = domainController.getLocalHostInfo().getLocalHostName();
   final ModelNode hostModel = domainModel.require(HOST).require(hostControllerName);
   return new ManagedServerBootCmdFactory(
       serverName, domainModel, hostModel, environment, domainController.getExpressionResolver());
 }
  public void addDeploymentOverlays(final List<ModelNode> updates) {
    if (domainModel.hasDefined(DEPLOYMENT_OVERLAY)) {

      HostFileRepository remoteRepository = null;
      if (!domainController.getLocalHostInfo().isMasterDomainController()) {
        remoteRepository = domainController.getRemoteFileRepository();
      }

      for (Property deploymentOverlay : domainModel.get(DEPLOYMENT_OVERLAY).asPropertyList()) {
        String name = deploymentOverlay.getName();
        ModelNode details = deploymentOverlay.getValue();

        PathAddress addr =
            PathAddress.pathAddress(PathElement.pathElement(DEPLOYMENT_OVERLAY, name));
        ModelNode addOp = Util.getEmptyOperation(ADD, addr.toModelNode());
        updates.add(addOp);

        if (details.hasDefined(CONTENT)) {

          for (Property content : details.get(CONTENT).asPropertyList()) {
            final String contentName = content.getName();
            final ModelNode contentDetails = content.getValue();
            byte[] hash = contentDetails.require(CONTENT).asBytes();
            File[] files = domainController.getLocalFileRepository().getDeploymentFiles(hash);
            if (files == null || files.length == 0) {
              if (remoteRepository != null) {
                remoteRepository.getDeploymentFiles(hash);
              }
            }
            addr =
                PathAddress.pathAddress(
                    PathElement.pathElement(DEPLOYMENT_OVERLAY, name),
                    PathElement.pathElement(CONTENT, contentName));
            addOp = Util.getEmptyOperation(ADD, addr.toModelNode());
            addOp.get(CONTENT).get(HASH).set(contentDetails.get(CONTENT));
            updates.add(addOp);
          }
        }
        if (serverGroup.hasDefined(DEPLOYMENT_OVERLAY)) {
          final ModelNode groupOverlay = serverGroup.get(DEPLOYMENT_OVERLAY).asObject();
          if (groupOverlay.has(name)) {
            ModelNode deploymentsNode = groupOverlay.get(name);
            if (deploymentsNode.has(DEPLOYMENT)) {
              for (Property content : deploymentsNode.get(DEPLOYMENT).asPropertyList()) {
                final String deploymentName = content.getName();
                final ModelNode deploymentDetails = content.getValue();
                addr =
                    PathAddress.pathAddress(
                        PathElement.pathElement(DEPLOYMENT_OVERLAY, name),
                        PathElement.pathElement(DEPLOYMENT, deploymentName));
                addOp = Util.getEmptyOperation(ADD, addr.toModelNode());
                updates.add(addOp);
              }
            }
          }
        }
      }
    }
  }
 private ManagedServer createManagedServer(final String serverName, final byte[] authKey) {
   final String hostControllerName = domainController.getLocalHostInfo().getLocalHostName();
   // final ManagedServerBootConfiguration configuration = combiner.createConfiguration();
   final Map<PathAddress, ModelVersion> subsystems =
       TransformerRegistry.resolveVersions(extensionRegistry);
   final ModelVersion modelVersion =
       ModelVersion.create(
           Version.MANAGEMENT_MAJOR_VERSION,
           Version.MANAGEMENT_MINOR_VERSION,
           Version.MANAGEMENT_MICRO_VERSION);
   // We don't need any transformation between host and server
   final TransformationTarget target =
       TransformationTargetImpl.create(
           extensionRegistry.getTransformerRegistry(),
           modelVersion,
           subsystems,
           null,
           TransformationTarget.TransformationTargetType.SERVER,
           null);
   return new ManagedServer(
       hostControllerName,
       serverName,
       authKey,
       processControllerClient,
       managementAddress,
       target);
 }
 @Override
 public void reconnectServer(
     final String serverName,
     final ModelNode domainModel,
     final byte[] authKey,
     final boolean running,
     final boolean stopping) {
   if (shutdown || connectionFinished) {
     throw HostControllerMessages.MESSAGES.hostAlreadyShutdown();
   }
   ManagedServer existing = servers.get(serverName);
   if (existing != null) {
     ROOT_LOGGER.existingServerWithState(serverName, existing.getState());
     return;
   }
   final ManagedServer server = createManagedServer(serverName, authKey);
   if ((existing = servers.putIfAbsent(serverName, server)) != null) {
     ROOT_LOGGER.existingServerWithState(serverName, existing.getState());
     return;
   }
   if (running) {
     if (!stopping) {
       server.reconnectServerProcess(createBootFactory(serverName, domainModel));
       // Register the server proxy at the domain controller
       domainController.registerRunningServer(server.getProxyController());
     } else {
       server.setServerProcessStopping();
     }
   } else {
     server.removeServerProcess();
   }
   synchronized (shutdownCondition) {
     shutdownCondition.notifyAll();
   }
 }
  private void addDeployments(List<ModelNode> updates) {
    if (serverGroup.hasDefined(DEPLOYMENT)) {

      HostFileRepository remoteRepository = null;
      if (!domainController.getLocalHostInfo().isMasterDomainController()) {
        remoteRepository = domainController.getRemoteFileRepository();
      }

      for (Property deployment : serverGroup.get(DEPLOYMENT).asPropertyList()) {
        String name = deployment.getName();
        ModelNode details = deployment.getValue();

        ModelNode domainDeployment = domainModel.require(DEPLOYMENT).require(name);
        ModelNode deploymentContent = domainDeployment.require(CONTENT).clone();

        if (remoteRepository != null) {
          // Make sure we have a copy of the deployment in the local repo
          for (ModelNode content : deploymentContent.asList()) {
            if ((content.hasDefined(HASH))) {
              byte[] hash = content.require(HASH).asBytes();
              File[] files = domainController.getLocalFileRepository().getDeploymentFiles(hash);
              if (files == null || files.length == 0) {
                remoteRepository.getDeploymentFiles(hash);
              }
            }
          }
        }

        PathAddress addr = PathAddress.pathAddress(PathElement.pathElement(DEPLOYMENT, name));
        ModelNode addOp = Util.getEmptyOperation(ADD, addr.toModelNode());
        addOp.get(RUNTIME_NAME).set(details.get(RUNTIME_NAME));
        addOp.get(CONTENT).set(deploymentContent);
        addOp.get(ENABLED).set(!details.hasDefined(ENABLED) || details.get(ENABLED).asBoolean());

        updates.add(addOp);
      }
    }
  }
 @Override
 public void serverProcessStopped(final String serverProcessName) {
   final String serverName = ManagedServer.getServerName(serverProcessName);
   final ManagedServer server = servers.get(serverName);
   if (server == null) {
     ROOT_LOGGER.noServerAvailable(serverName);
     return;
   }
   // always un-register in case the process exits
   domainController.unregisterRunningServer(server.getServerName());
   server.processFinished();
   synchronized (shutdownCondition) {
     shutdownCondition.notifyAll();
   }
 }
 private void addSystemProperties(
     final ModelNode source, final Map<String, String> props, boolean boottimeOnly) {
   if (source.hasDefined(SYSTEM_PROPERTY)) {
     for (Property prop : source.get(SYSTEM_PROPERTY).asPropertyList()) {
       ModelNode propResource = prop.getValue();
       try {
         if (boottimeOnly
             && !SystemPropertyResourceDefinition.BOOT_TIME
                 .resolveModelAttribute(domainController.getExpressionResolver(), propResource)
                 .asBoolean()) {
           continue;
         }
       } catch (OperationFailedException e) {
         throw new IllegalStateException(e);
       }
       String val = propResource.hasDefined(VALUE) ? propResource.get(VALUE).asString() : null;
       props.put(prop.getName(), val);
     }
   }
 }
 private void addSubsystems(List<ModelNode> updates) {
   ModelNode node = domainController.getProfileOperations(profileName);
   updates.addAll(node.asList());
 }