@Override public void deleteModule(DatasetModuleId moduleId) throws DatasetManagementException { clientCache.getUnchecked(moduleId.getParent()).deleteModule(moduleId.getEntityName()); }
@Override public void deleteModule(DatasetModuleId moduleId) throws DatasetManagementException { clientCache.getUnchecked(moduleId.getParent()).deleteModule(moduleId.getEntityName()); }
@Override public void addModule(DatasetModuleId moduleId, DatasetModule module, Location jarLocation) throws DatasetManagementException { clientCache.getUnchecked(moduleId.getParent()) .addModule(moduleId.getEntityName(), DatasetModules.getDatasetModuleClass(module).getName(), jarLocation); }
@Override public void addModule(DatasetModuleId moduleId, DatasetModule module, Location jarLocation) throws DatasetManagementException { clientCache.getUnchecked(moduleId.getParent()) .addModule(moduleId.getEntityName(), DatasetModules.getDatasetModuleClass(module).getName(), jarLocation); }
/** * Retrieves a module from the given namespace * * @param datasetModuleId the {@link DatasetModuleId} for the module to retrieve * @return {@link DatasetModuleMeta} for the module if found in the specified namespace, null otherwise */ @Nullable public DatasetModuleMeta getModule(DatasetModuleId datasetModuleId) { return get(getModuleKey(datasetModuleId.getNamespace(), datasetModuleId.getEntityName()), DatasetModuleMeta.class); }
/** * Retrieves a module from the given namespace * * @param datasetModuleId the {@link DatasetModuleId} for the module to retrieve * @return {@link DatasetModuleMeta} for the module if found in the specified namespace, null otherwise */ @Nullable public DatasetModuleMeta getModule(DatasetModuleId datasetModuleId) { return get(getModuleKey(datasetModuleId.getNamespace(), datasetModuleId.getEntityName()), DatasetModuleMeta.class); }
/** * Tries to find a module in the specified namespace first. If it fails, tries to find it in the system namespace * * @param datasetModuleId {@link DatasetModuleId} for the module to retrieve * @return {@link DatasetModuleMeta} for the module if found either in the specified namespace or in the system * namespace, null otherwise */ @Nullable public DatasetModuleMeta getModuleWithFallback(DatasetModuleId datasetModuleId) { // Try to find module in the specified namespace first DatasetModuleMeta moduleMeta = getModule(datasetModuleId); // if not found, try to load it from system namespace if (moduleMeta == null) { moduleMeta = getModule(NamespaceId.SYSTEM.datasetModule(datasetModuleId.getEntityName())); } return moduleMeta; }
/** * Tries to find a module in the specified namespace first. If it fails, tries to find it in the system namespace * * @param datasetModuleId {@link DatasetModuleId} for the module to retrieve * @return {@link DatasetModuleMeta} for the module if found either in the specified namespace or in the system * namespace, null otherwise */ @Nullable public DatasetModuleMeta getModuleWithFallback(DatasetModuleId datasetModuleId) { // Try to find module in the specified namespace first DatasetModuleMeta moduleMeta = getModule(datasetModuleId); // if not found, try to load it from system namespace if (moduleMeta == null) { moduleMeta = getModule(NamespaceId.SYSTEM.datasetModule(datasetModuleId.getEntityName())); } return moduleMeta; }
@Override public void addModule(DatasetModuleId moduleId, DatasetModule module) throws DatasetManagementException { Class<?> moduleClass = DatasetModules.getDatasetModuleClass(module); try { Location deploymentJar = createDeploymentJar(moduleClass); try { clientCache.getUnchecked(moduleId.getParent()) .addModule(moduleId.getEntityName(), moduleClass.getName(), deploymentJar); } finally { try { deploymentJar.delete(); } catch (IOException e) { // Just log warning, since the add module operation can still proceed LOG.warn("Failed to delete temporary deployment jar {}", deploymentJar, e); } } } catch (IOException e) { String msg = String.format("Could not create jar for deploying dataset module %s with main class %s", moduleId, moduleClass.getName()); LOG.error(msg, e); throw new DatasetManagementException(msg, e); } }
@Override public void addModule(DatasetModuleId moduleId, DatasetModule module) throws DatasetManagementException { Class<?> moduleClass = DatasetModules.getDatasetModuleClass(module); try { Location deploymentJar = createDeploymentJar(moduleClass); try { clientCache.getUnchecked(moduleId.getParent()) .addModule(moduleId.getEntityName(), moduleClass.getName(), deploymentJar); } finally { try { deploymentJar.delete(); } catch (IOException e) { // Just log warning, since the add module operation can still proceed LOG.warn("Failed to delete temporary deployment jar {}", deploymentJar, e); } } } catch (IOException e) { String msg = String.format("Could not create jar for deploying dataset module %s with main class %s", moduleId, moduleClass.getName()); LOG.error(msg, e); throw new DatasetManagementException(msg, e); } }
@Override public void perform(Arguments arguments, PrintStream output) throws Exception { DatasetModuleId module = cliConfig.getCurrentNamespace().datasetModule( arguments.get(ArgumentName.DATASET_MODULE.toString())); datasetClient.delete(module); output.printf("Successfully deleted dataset module '%s'\n", module.getEntityName()); }
@Override public void perform(Arguments arguments, PrintStream output) throws Exception { DatasetModuleId module = cliConfig.getCurrentNamespace().datasetModule( arguments.get(ArgumentName.DATASET_MODULE.toString())); datasetClient.delete(module); output.printf("Successfully deleted dataset module '%s'\n", module.getEntityName()); }
@Override public void add(DatasetDefinition def) { String typeName = def.getName(); DatasetTypeId typeId = getNamespaceId().datasetType(typeName); DatasetTypeMeta existingType = datasetTypeMDS.getType(typeId); if (existingType != null) { DatasetModuleMeta existingModule = existingType.getModules().get(existingType.getModules().size() - 1); // we allow redefining an existing type if // - it was previously defined by the same module (i.e., this is an upgrade of that module) // - it is a forced update and the existing type is not a system type if (!moduleBeingAdded.getEntityName().equals(existingModule.getName()) && (!tolerateConflicts || NamespaceId.SYSTEM.getNamespace().equals(existingModule.getName()))) { throw new TypeConflictException(String.format( "Attempt to add dataset module '%s' containing dataset type '%s' that already exists in module '%s'", moduleBeingAdded.getEntityName(), typeName, existingModule.getName())); } } types.add(typeName); registry.add(def); }
@Override public void add(DatasetDefinition def) { String typeName = def.getName(); DatasetTypeId typeId = getNamespaceId().datasetType(typeName); DatasetTypeMeta existingType = datasetTypeMDS.getType(typeId); if (existingType != null) { DatasetModuleMeta existingModule = existingType.getModules().get(existingType.getModules().size() - 1); // we allow redefining an existing type if // - it was previously defined by the same module (i.e., this is an upgrade of that module) // - it is a forced update and the existing type is not a system type if (!moduleBeingAdded.getEntityName().equals(existingModule.getName()) && (!tolerateConflicts || NamespaceId.SYSTEM.getNamespace().equals(existingModule.getName()))) { throw new TypeConflictException(String.format( "Attempt to add dataset module '%s' containing dataset type '%s' that already exists in module '%s'", moduleBeingAdded.getEntityName(), typeName, existingModule.getName())); } } types.add(typeName); registry.add(def); }
@Override public void addModule(DatasetModuleId moduleId, DatasetModule module) throws ModuleConflictException { // TODO (CDAP-6297): check if existing modules overlap, or if this removes a type other modules depend on writeLock.lock(); try { DatasetDefinitionRegistry registry = registries.get(moduleId.getParent()); if (registry == null) { registry = registryFactory.create(); registries.put(moduleId.getParent(), registry); } TypesTrackingRegistry trackingRegistry = new TypesTrackingRegistry(registry); module.register(trackingRegistry); String moduleClassName = DatasetModules.getDatasetModuleClass(module).getName(); moduleClasses.put(moduleId.getParent(), moduleId, moduleClassName); List<String> types = trackingRegistry.getTypes(); nonDefaultTypes.putAll(moduleId.getParent(), types); for (String type : types) { this.types.put(moduleId.getParent().datasetType(type), new DatasetTypeMeta(type, Collections.singletonList( new DatasetModuleMeta(moduleId.getEntityName(), moduleClassName, null, types, Collections.<String>emptyList())))); } } finally { writeLock.unlock(); } }
public void deleteModule(DatasetModuleId datasetModuleId) { DatasetModuleMeta module = getModule(datasetModuleId); if (module == null) { // that's fine: module is not there return; } deleteAll(getModuleKey(datasetModuleId.getNamespace(), datasetModuleId.getEntityName())); for (String type : module.getTypes()) { deleteAll(getTypeKey(datasetModuleId.getNamespace(), type)); } }
public void deleteModule(DatasetModuleId datasetModuleId) { DatasetModuleMeta module = getModule(datasetModuleId); if (module == null) { // that's fine: module is not there return; } deleteAll(getModuleKey(datasetModuleId.getNamespace(), datasetModuleId.getEntityName())); for (String type : module.getTypes()) { deleteAll(getTypeKey(datasetModuleId.getNamespace(), type)); } }
private HttpResponse makeModuleInfoRequest(DatasetModuleId module) throws IOException { HttpRequest request = HttpRequest.get(getUrl(module.getNamespace(), "/data/modules/" + module.getEntityName())).build(); return HttpRequests.execute(request); }
protected HttpResponse deleteModule(DatasetModuleId module) throws Exception { return HttpRequests.execute( HttpRequest.delete(getUrl(module.getNamespace(), "/data/modules/" + module.getEntityName())).build()); }
protected HttpResponse deployModule(DatasetModuleId module, Class moduleClass, boolean force) throws Exception { Location moduleJar = createModuleJar(moduleClass); String urlPath = "/data/modules/" + module.getEntityName(); urlPath = force ? urlPath + "?force=true" : urlPath; HttpRequest request = HttpRequest.put(getUrl(module.getNamespace(), urlPath)) .addHeader("X-Class-Name", moduleClass.getName()) .withBody((ContentProvider<? extends InputStream>) moduleJar::getInputStream).build(); return HttpRequests.execute(request); }