@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);
 }
Beispiel #2
0
 @Override
 public void validateBeforeSave(String name, String definition) {
   Assert.hasText(name, "name cannot be blank or null");
   D definitionFromRepo = getDefinitionRepository().findOne(name);
   if (definitionFromRepo != null) {
     throwDefinitionAlreadyExistsException(definitionFromRepo);
   }
   Assert.hasText(definition, "definition cannot be blank or null");
   parser.parse(name, definition, definitionKind);
 }
Beispiel #3
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);
  }
Beispiel #4
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));
   }
 }
  /**
   * {@inheritDoc}
   *
   * <p>Before deleting the stream, perform an undeploy. This causes a graceful shutdown of the
   * modules in the stream before it is deleted from the repository.
   */
  @Override
  protected void beforeDelete(StreamDefinition definition) {
    super.beforeDelete(definition);

    // Load module definitions and set them on StreamDefinition; this is used by
    // StreamDefinitionRepositoryUtils.deleteDependencies to delete dependent modules

    // todo: this parsing and setting of ModuleDefinitions should not be needed once we refactor the
    // ModuleDependencyRepository so that the dependencies are also stored in ZooKeeper.
    List<ModuleDefinition> moduleDefinitions = new ArrayList<ModuleDefinition>();
    try {
      for (ModuleDescriptor request :
          parser.parse(definition.getName(), definition.getDefinition(), ParsingContext.stream)) {
        moduleDefinitions.add(new ModuleDefinition(request.getModuleName(), request.getType()));
      }
    } catch (StreamDefinitionException e) {
      // we can ignore an exception for a tap whose stream no longer exists
      if (!(XDDSLMessages.UNRECOGNIZED_STREAM_REFERENCE.equals(e.getMessageCode())
          && definition.getDefinition().trim().startsWith("tap:"))) {
        throw e;
      }
    }
    definition.setModuleDefinitions(moduleDefinitions);
  }
 protected List<ModuleDeploymentRequest> parse(String name, String config) {
   return streamParser.parse(name, config);
 }