Package org.springframework.xd.dirt.core

Examples of org.springframework.xd.dirt.core.DeploymentUnitStatus


    try {
      String deploymentPath = getDeploymentPath(definition);
      String statusPath = Paths.build(deploymentPath, Paths.STATUS);
      byte[] propertyBytes = DeploymentPropertiesUtility.formatDeploymentProperties(properties).getBytes("UTF-8");
      byte[] statusBytes = ZooKeeperUtils.mapToBytes(
          new DeploymentUnitStatus(DeploymentUnitStatus.State.deploying).toMap());

      zkConnection.getClient().inTransaction()
          .create().forPath(deploymentPath, propertyBytes).and()
          .create().withMode(CreateMode.EPHEMERAL).forPath(statusPath, statusBytes).and()
          .commit();
View Full Code Here


    }

    logger.trace("moduleCountMap after evaluation: {}", moduleCount);

    if (moduleCount.isEmpty()) {
      return new DeploymentUnitStatus(DeploymentUnitStatus.State.deployed, builder.toString());
    }

    // since there are some modules that did not meet the expected count,
    // iterate the map and determine if any modules failed to deploy at all;
    // if each module type has at least one deployment the status is considered
    // incomplete
    boolean failed = false;
    for (Count count : moduleCount.values()) {
      if (count.actual == 0) {
        failed = true;
        break;
      }
    }

    DeploymentUnitStatus.State state = (failed)
        ? DeploymentUnitStatus.State.failed
        : DeploymentUnitStatus.State.incomplete;

    return new DeploymentUnitStatus(state, builder.toString());
  }
View Full Code Here

      if (data != null) {
        Map<String, String> metadataMap = ZooKeeperUtils.bytesToMap(data);
        ModuleDeploymentsPath p = new ModuleDeploymentsPath(moduleDeploymentPath);
        ModuleType moduleType = id.getModuleType();

        DeploymentUnitStatus status = moduleType == ModuleType.job
            ? jobRepository.getDeploymentStatus(id.getUnitName())
            : streamRepository.getDeploymentStatus(id.getUnitName());

        metadata = new ModuleMetadata(id,
            getResolvedModuleOptions(metadataMap),
            getDeploymentProperties(moduleDeploymentPath),
            status.getState());
      }
    }
    catch (Exception e) {
      // NoNodeException - this node does not exist, will return null
      ZooKeeperUtils.wrapAndThrowIgnoring(e, NoNodeException.class);
View Full Code Here

        ZooKeeperUtils.wrapAndThrowIgnoring(e, KeeperException.NodeExistsException.class);
      }

      String statusPath = Paths.build(Paths.JOB_DEPLOYMENTS, job.getName(), Paths.STATUS);

      DeploymentUnitStatus deployingStatus = null;
      try {
        deployingStatus = new DeploymentUnitStatus(ZooKeeperUtils.bytesToMap(
            client.getData().forPath(statusPath)));
      }
      catch (Exception e) {
        // an exception indicates that the status has not been set
      }
      Assert.state(deployingStatus != null
          && deployingStatus.getState() == DeploymentUnitStatus.State.deploying,
          String.format("Expected 'deploying' status for job '%s'; current status: %s",
              job.getName(), deployingStatus));

      ModuleDeploymentPropertiesProvider<ModuleDeploymentProperties> provider =
          new DefaultModuleDeploymentPropertiesProvider(job);

      try {
        Collection<ModuleDeploymentStatus> deploymentStatuses = new ArrayList<ModuleDeploymentStatus>();
        for (ModuleDescriptor descriptor : job.getModuleDescriptors()) {
          RuntimeModuleDeploymentProperties deploymentProperties = new RuntimeModuleDeploymentProperties();
          deploymentProperties.putAll(provider.propertiesForDescriptor(descriptor));
          Deque<Container> matchedContainers = new ArrayDeque<Container>(containerMatcher.match(descriptor,
              deploymentProperties,
              containerRepository.findAll()));
          // Modules count == 0
          if (deploymentProperties.getCount() == 0) {
            deploymentProperties.setSequence(0);
            createModuleDeploymentRequestsPath(client, descriptor, deploymentProperties);
          }
          // Modules count > 0
          else {
            for (int i = 1; i <= deploymentProperties.getCount(); i++) {
              deploymentProperties.setSequence(i);
              createModuleDeploymentRequestsPath(client, descriptor, deploymentProperties);
            }
          }
          RuntimeModuleDeploymentPropertiesProvider deploymentRuntimeProvider =
              new RuntimeModuleDeploymentPropertiesProvider(provider);

          try {
            deploymentStatuses.addAll(moduleDeploymentWriter.writeDeployment(
                descriptor, deploymentRuntimeProvider, matchedContainers));
          }
          catch (NoContainerException e) {
            logger.warn("No containers available for deployment of job {}", job.getName());
          }

          DeploymentUnitStatus status = stateCalculator.calculate(job, provider, deploymentStatuses);

          logger.info("Deployment status for job '{}': {}", job.getName(), status);

          client.setData().forPath(statusPath, ZooKeeperUtils.mapToBytes(status.toMap()));
        }
      }
      catch (InterruptedException e) {
        throw e;
      }
View Full Code Here

              jobDeploymentsPath.getContainer(),
              jobDeploymentsPath.getModuleSequence(),
              new ModuleDescriptor.Key(jobName, ModuleType.job, jobDeploymentsPath.getModuleLabel()),
              ModuleDeploymentStatus.State.deployed, null));
        }
        DeploymentUnitStatus status = stateCalculator.calculate(job,
            new DefaultModuleDeploymentPropertiesProvider(job), statusList);

        logger.info("Deployment status for job '{}': {}", job.getName(), status);

        String statusPath = Paths.build(Paths.JOB_DEPLOYMENTS, job.getName(), Paths.STATUS);
        Stat stat = client.checkExists().forPath(statusPath);
        if (stat != null) {
          logger.trace("Found old status path {}; stat: {}", statusPath, stat);
          client.delete().forPath(statusPath);
        }
        client.create().withMode(CreateMode.EPHEMERAL).forPath(statusPath,
            ZooKeeperUtils.mapToBytes(status.toMap()));
      }
    }
  }
View Full Code Here

        ? Paths.STREAM_DEPLOYMENTS
        : Paths.JOB_DEPLOYMENTS;

    getClient().setData().forPath(
        Paths.build(pathPrefix, deploymentUnit.getName(), Paths.STATUS),
        ZooKeeperUtils.mapToBytes(new DeploymentUnitStatus(
            DeploymentUnitStatus.State.deploying).toMap()));
  }
View Full Code Here

    boolean isStream = (deploymentUnit instanceof Stream);

    ModuleDeploymentPropertiesProvider<ModuleDeploymentProperties> provider = new DefaultModuleDeploymentPropertiesProvider(
        deploymentUnit);

    DeploymentUnitStatus status = stateCalculator.calculate(deploymentUnit, provider, aggregateStatuses);

    logger.info("Deployment state for {} '{}': {}",
        isStream ? "stream" : "job", deploymentUnit.getName(), status);

    getClient().setData().forPath(
        Paths.build(isStream ? Paths.STREAM_DEPLOYMENTS : Paths.JOB_DEPLOYMENTS,
            deploymentUnit.getName(), Paths.STATUS),
        ZooKeeperUtils.mapToBytes(status.toMap()));
  }
View Full Code Here

    }

    String statusPath = Paths.build(Paths.STREAM_DEPLOYMENTS, stream.getName(), Paths.STATUS);

    // assert that the deployment status has been correctly set to "deploying"
    DeploymentUnitStatus deployingStatus = null;
    try {
      deployingStatus = new DeploymentUnitStatus(ZooKeeperUtils.bytesToMap(
          client.getData().forPath(statusPath)));
    }
    catch (Exception e) {
      // an exception indicates that the status has not been set
    }
    Assert.state(deployingStatus != null
        && deployingStatus.getState() == DeploymentUnitStatus.State.deploying,
        String.format("Expected 'deploying' status for stream '%s'; current status: %s",
            stream.getName(), deployingStatus));

    try {
      Collection<ModuleDeploymentStatus> deploymentStatuses = new ArrayList<ModuleDeploymentStatus>();
      DefaultModuleDeploymentPropertiesProvider deploymentPropertiesProvider =
          new DefaultModuleDeploymentPropertiesProvider(stream);
      for (Iterator<ModuleDescriptor> descriptors = stream.getDeploymentOrderIterator(); descriptors.hasNext();) {
        ModuleDescriptor descriptor = descriptors.next();
        ModuleDeploymentProperties deploymentProperties = deploymentPropertiesProvider.propertiesForDescriptor(descriptor);

        // write out all of the required modules for this stream (including runtime properties);
        // this does not actually perform a deployment...this data is used in case there are not
        // enough containers to deploy the stream
        StreamRuntimePropertiesProvider partitionPropertiesProvider =
            new StreamRuntimePropertiesProvider(stream, deploymentPropertiesProvider);
        int moduleCount = deploymentProperties.getCount();
        if (moduleCount == 0) {
          createModuleDeploymentRequestsPath(client, descriptor,
              partitionPropertiesProvider.propertiesForDescriptor(descriptor));
        }
        else {
          for (int i = 0; i < moduleCount; i++) {
            createModuleDeploymentRequestsPath(client, descriptor,
                partitionPropertiesProvider.propertiesForDescriptor(descriptor));
          }
        }

        try {
          // find the containers that can deploy these modules
          Collection<Container> containers = containerMatcher.match(descriptor, deploymentProperties,
              containerRepository.findAll());

          // write out the deployment requests targeted to the containers obtained above;
          // a new instance of StreamPartitionPropertiesProvider is created since this
          // object is responsible for generating unique sequence ids for modules
          StreamRuntimePropertiesProvider deploymentRuntimeProvider =
              new StreamRuntimePropertiesProvider(stream, deploymentPropertiesProvider);

          deploymentStatuses.addAll(moduleDeploymentWriter.writeDeployment(
              descriptor, deploymentRuntimeProvider, containers));
        }
        catch (NoContainerException e) {
          logger.warn("No containers available for deployment of module '{}' for stream '{}'",
              descriptor.getModuleLabel(), stream.getName());
        }
      }

      DeploymentUnitStatus status = stateCalculator.calculate(stream, deploymentPropertiesProvider,
          deploymentStatuses);
      logger.info("Deployment status for stream '{}': {}", stream.getName(), status);

      client.setData().forPath(statusPath, ZooKeeperUtils.mapToBytes(status.toMap()));
    }
    catch (InterruptedException e) {
      throw e;
    }
    catch (Exception e) {
View Full Code Here

        catch (KeeperException.NoNodeException e) {
          // indicates there are no modules deployed for this stream;
          // ignore as this will result in an empty statusList
        }

        DeploymentUnitStatus status = stateCalculator.calculate(stream,
            new DefaultModuleDeploymentPropertiesProvider(stream), statusList);

        logger.info("Deployment status for stream '{}': {}", stream.getName(), status);

        String statusPath = Paths.build(Paths.STREAM_DEPLOYMENTS, stream.getName(), Paths.STATUS);
        Stat stat = client.checkExists().forPath(statusPath);
        if (stat != null) {
          logger.trace("Found old status path {}; stat: {}", statusPath, stat);
          client.delete().forPath(statusPath);
        }
        client.create().withMode(CreateMode.EPHEMERAL).forPath(statusPath,
            ZooKeeperUtils.mapToBytes(status.toMap()));
      }
    }
  }
View Full Code Here

    Deque<String> paths = new ArrayDeque<String>();

    try {
      client.setData().forPath(
          Paths.build(Paths.STREAM_DEPLOYMENTS, id, Paths.STATUS),
          ZooKeeperUtils.mapToBytes(new DeploymentUnitStatus(
              DeploymentUnitStatus.State.undeploying).toMap()));
    }
    catch (Exception e) {
      logger.warn("Exception while transitioning stream {} state to {}", id,
          DeploymentUnitStatus.State.undeploying, e);
View Full Code Here

TOP

Related Classes of org.springframework.xd.dirt.core.DeploymentUnitStatus

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.