Package co.cask.cdap.proto

Examples of co.cask.cdap.proto.DatasetModuleMeta


  @Override
  public void process(String[] args, PrintStream output) throws Exception {
    super.process(args, output);

    String moduleName = args[0];
    DatasetModuleMeta datasetModuleMeta = datasetModuleClient.get(moduleName);

    new AsciiTable<DatasetModuleMeta>(
      new String[] { "name", "className", "jarLocation", "types", "usesModules", "usedByModules" },
      Lists.newArrayList(datasetModuleMeta),
      new RowMaker<DatasetModuleMeta>() {
View Full Code Here


    }
    return getModule(moduleName);
  }

  public DatasetTypeMeta getType(String typeName) {
    DatasetModuleMeta moduleName = getModuleByType(typeName);
    if (moduleName == null) {
      return null;
    }
    return getTypeMeta(typeName, moduleName);
  }
View Full Code Here

      write(type, moduleMeta.getName());
    }
  }

  public void deleteModule(String name) {
    DatasetModuleMeta module = getModule(name);
    if (module == null) {
      // that's fine: module is not there
      return;
    }

    delete(getModuleKey(module.getName()));

    for (String type : module.getTypes()) {
      delete(getTypeKey(type));
    }
  }
View Full Code Here

      delete(getTypeKey(type));
    }
  }

  private DatasetTypeMeta getTypeMeta(String typeName, String moduleName) {
    DatasetModuleMeta moduleMeta = getModule(moduleName);
    return getTypeMeta(typeName, moduleMeta);
  }
View Full Code Here

    String className = request.getHeader(HEADER_CLASS_NAME);
    Preconditions.checkArgument(className != null, "Required header 'class-name' is absent.");
    LOG.info("Adding module {}, class name: {}", name, className);

    DatasetModuleMeta existing = manager.getModule(name);
    if (existing != null) {
      String message = String.format("Cannot add module %s: module with same name already exists: %s",
                                     name, existing);
      LOG.warn(message);
      responder.sendError(HttpResponseStatus.CONFLICT, message);
View Full Code Here

  }

  @GET
  @Path("/data/modules/{name}")
  public void getModuleInfo(HttpRequest request, final HttpResponder responder, @PathParam("name") String name) {
    DatasetModuleMeta moduleMeta = manager.getModule(name);
    if (moduleMeta == null) {
      responder.sendStatus(HttpResponseStatus.NOT_FOUND);
    } else {
      responder.sendJson(HttpResponseStatus.OK, moduleMeta);
    }
View Full Code Here

    try {
      mdsDatasets.execute(new TxCallable<MDSDatasets, Void>() {
        @Override
        public Void call(MDSDatasets datasets) throws DatasetModuleConflictException {
          DatasetModuleMeta existing = datasets.getTypeMDS().getModule(name);
          if (existing != null) {
            String msg = String.format("cannot add module %s, module with the same name already exists: %s",
                                       name, existing);
            LOG.warn(msg);
            throw new DatasetModuleConflictException(msg);
          }

          ClassLoader cl;
          DatasetModule module;
          File unpackedLocation = Files.createTempDir();
          DependencyTrackingRegistry reg;
          try {
            // NOTE: if jarLocation is null, we assume that this is a system module, ie. always present in classpath
            if (jarLocation != null) {
              BundleJarUtil.unpackProgramJar(jarLocation, unpackedLocation);
            }
            cl = jarLocation == null ? this.getClass().getClassLoader() :
              ClassLoaders.newProgramClassLoader(unpackedLocation, ApiResourceListHolder.getResourceList(),
                                                 this.getClass().getClassLoader());
            @SuppressWarnings("unchecked")
            Class clazz = ClassLoaders.loadClass(className, cl, this);
            module = DatasetModules.getDatasetModule(clazz);
            reg = new DependencyTrackingRegistry(datasets);
            module.register(reg);
          } catch (Exception e) {
            LOG.error("Could not instantiate instance of dataset module class {} for module {} using jarLocation {}",
                      className, name, jarLocation);
            throw Throwables.propagate(e);
          } finally {
            try {
              DirUtils.deleteDirectoryContents(unpackedLocation);
            } catch (IOException e) {
              LOG.warn("Failed to delete directory {}", unpackedLocation, e);
            }
          }
          // NOTE: we use set to avoid duplicated dependencies
          // NOTE: we use LinkedHashSet to preserve order in which dependencies must be loaded
          Set<String> moduleDependencies = Sets.newLinkedHashSet();
          for (String usedType : reg.getUsedTypes()) {
            DatasetModuleMeta usedModule = datasets.getTypeMDS().getModuleByType(usedType);
            // adding all used types and the module itself, in this very order to keep the order of loading modules
            // for instantiating a type
            moduleDependencies.addAll(usedModule.getUsesModules());
            boolean added = moduleDependencies.add(usedModule.getName());
            if (added) {
              // also adding this module as a dependent for all modules it uses
              usedModule.addUsedByModule(name);
              datasets.getTypeMDS().write(usedModule);
            }
          }

          DatasetModuleMeta moduleMeta = new DatasetModuleMeta(name, className,
                                                               jarLocation == null ? null : jarLocation.toURI(),
                                                               reg.getTypes(), Lists.newArrayList(moduleDependencies));
          datasets.getTypeMDS().write(moduleMeta);

          return null;
View Full Code Here

    LOG.info("Deleting module {}", name);
    try {
      return mdsDatasets.execute(new TxCallable<MDSDatasets, Boolean>() {
        @Override
        public Boolean call(MDSDatasets datasets) throws DatasetModuleConflictException {
          DatasetModuleMeta module = datasets.getTypeMDS().getModule(name);

          if (module == null) {
            return false;
          }

          // cannot delete when there's module that uses it
          if (module.getUsedByModules().size() > 0) {
            String msg =
              String.format("Cannot delete module %s: other modules depend on it. Delete them first", module);
            throw new DatasetModuleConflictException(msg);
          }

          Collection<DatasetSpecification> dependentInstances =
            datasets.getInstanceMDS().getByTypes(ImmutableSet.copyOf(module.getTypes()));
          // cannot delete when there's instance that uses it
          if (dependentInstances.size() > 0) {
            String msg =
              String.format("Cannot delete module %s: other instances depend on it. Delete them first", module);
            throw new DatasetModuleConflictException(msg);
          }

          // remove it from "usedBy" from other modules
          for (String usedModuleName : module.getUsesModules()) {
            DatasetModuleMeta usedModule = datasets.getTypeMDS().getModule(usedModuleName);
            usedModule.removeUsedByModule(name);
            datasets.getTypeMDS().write(usedModule);
          }

          datasets.getTypeMDS().deleteModule(name);
View Full Code Here

TOP

Related Classes of co.cask.cdap.proto.DatasetModuleMeta

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.