Esempio n. 1
0
 @Override
 public D save(D definition) {
   Assert.notNull(definition, "Definition may not be null");
   if (repository.findOne(definition.getName()) != null) {
     throwDefinitionAlreadyExistsException(definition);
   }
   streamParser.parse(definition.getName(), definition.getDefinition());
   return repository.save(definition);
 }
Esempio n. 2
0
 /**
  * Provides basic un-deployment behavior, whereby state of deployed definitions is not dealt with.
  */
 protected void basicUndeploy(String name) {
   D definition = getDefinitionRepository().findOne(name);
   if (definition == null) {
     throwNoSuchDefinitionException(name);
   }
   List<ModuleDeploymentRequest> requests = parse(name, definition.getDefinition());
   for (ModuleDeploymentRequest request : requests) {
     request.setRemove(true);
   }
   Collections.reverse(requests);
   sendDeploymentRequests(name, requests);
 }
Esempio n. 3
0
  /**
   * Provides basic deployment behavior, whereby running state of deployed definitions is not
   * persisted.
   *
   * @return the definition object for the given name
   * @throws NoSuchDefinitionException if there is no definition by the given name
   */
  protected D basicDeploy(String name) {
    Assert.hasText(name, "name cannot be blank or null");
    final D definition = getDefinitionRepository().findOne(name);

    if (definition == null) {
      throwNoSuchDefinitionException(name);
    }

    final List<ModuleDeploymentRequest> requests = parse(name, definition.getDefinition());
    sendDeploymentRequests(name, requests);
    return definition;
  }
Esempio n. 4
0
  @Override
  public D save(D definition) {
    Assert.notNull(definition, "Definition may not be null");
    String name = definition.getName();
    String def = definition.getDefinition();
    validateBeforeSave(name, def);
    List<ModuleDescriptor> moduleDescriptors = parser.parse(name, def, definitionKind);

    // todo: the result of parse() should already have correct (polymorphic) definitions
    List<ModuleDefinition> moduleDefinitions = createModuleDefinitions(moduleDescriptors);
    if (!moduleDefinitions.isEmpty()) {
      definition.setModuleDefinitions(moduleDefinitions);
    }
    D savedDefinition = repository.save(definition);
    return afterSave(savedDefinition);
  }
Esempio n. 5
0
 /**
  * Validates that all deployment properties (of the form "module.<modulename>.<key>" do indeed
  * reference module names that belong to the stream/job definition).
  */
 private void validateDeploymentProperties(D definition, Map<String, String> properties) {
   List<ModuleDescriptor> modules =
       parser.parse(definition.getName(), definition.getDefinition(), definitionKind);
   Set<String> moduleLabels = new HashSet<String>(modules.size());
   for (ModuleDescriptor md : modules) {
     moduleLabels.add(md.getModuleLabel());
   }
   for (Map.Entry<String, String> pair : properties.entrySet()) {
     Matcher matcher = DEPLOYMENT_PROPERTY_PATTERN.matcher(pair.getKey());
     Assert.isTrue(
         matcher.matches(),
         String.format("'%s' does not match '%s'", pair.getKey(), DEPLOYMENT_PROPERTY_PATTERN));
     String moduleName = matcher.group(1);
     Assert.isTrue(
         "*".equals(moduleName) || moduleLabels.contains(moduleName),
         String.format(
             "'%s' refers to a module that is not in the list: %s", pair.getKey(), moduleLabels));
   }
 }