@Override
  public <S extends StreamDefinition> S save(S entity) {
    try {
      Map<String, String> map = new HashMap<>();
      map.put(DEFINITION_KEY, entity.getDefinition());

      map.put(
          MODULE_DEFINITIONS_KEY, objectWriter.writeValueAsString(entity.getModuleDefinitions()));

      CuratorFramework client = zkConnection.getClient();
      String path = Paths.build(Paths.STREAMS, entity.getName());
      byte[] binary = ZooKeeperUtils.mapToBytes(map);

      BackgroundPathAndBytesable<?> op =
          client.checkExists().forPath(path) == null ? client.create() : client.setData();

      op.forPath(path, binary);

      logger.trace("Saved stream {} with properties {}", path, map);

      StreamDefinitionRepositoryUtils.saveDependencies(moduleDependencyRepository, entity);
    } catch (Exception e) {
      // NodeExistsException indicates that we tried to create the
      // path just after another thread/jvm successfully created it
      ZooKeeperUtils.wrapAndThrowIgnoring(e, NodeExistsException.class);
    }
    return entity;
  }
 @Override
 public void delete(StreamDefinition entity) {
   StreamDefinitionRepositoryUtils.deleteDependencies(moduleDependencyRepository, entity);
   this.delete(entity.getName());
 }