@Override public String getEntityName() { return getModule(); }
@Override public String getEntityName() { return getModule(); }
public static DatasetModule fromEntityId(DatasetModuleId moduleId) { return from(Id.Namespace.fromEntityId(moduleId.getNamespaceId()), moduleId.getModule()); } }
public static DatasetModule fromEntityId(DatasetModuleId moduleId) { return from(Id.Namespace.fromEntityId(moduleId.getNamespaceId()), moduleId.getModule()); } }
/** * Checks if a dataset module exists. * * @param module the dataset module to check * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public boolean exists(DatasetModuleId module) throws IOException, UnauthenticatedException, UnauthorizedException { URL url = config.resolveNamespacedURLV3(module.getParent(), String.format("data/modules/%s", module.getModule())); HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); return response.getResponseCode() != HttpURLConnection.HTTP_NOT_FOUND; }
String moduleName = datasetModuleId.getModule(); Location archiveDir = namespaceHomeLocation.append(dataFabricDir).append(moduleName) .append(Constants.ARCHIVE_DIR);
String moduleName = datasetModuleId.getModule(); Location archiveDir = namespaceHomeLocation.append(dataFabricDir).append(moduleName) .append(Constants.ARCHIVE_DIR);
/** * Deletes the specified {@link DatasetModuleId} */ @Override public void delete(DatasetModuleId datasetModuleId) throws Exception { NamespaceId namespaceId = datasetModuleId.getParent(); if (NamespaceId.SYSTEM.equals(namespaceId)) { throw new UnsupportedOperationException( String.format("Cannot delete module '%s' from '%s' namespace.", datasetModuleId.getModule(), datasetModuleId.getNamespace())); } ensureNamespaceExists(namespaceId); DatasetModuleMeta moduleMeta = typeManager.getModule(datasetModuleId); if (moduleMeta == null) { throw new DatasetModuleNotFoundException(datasetModuleId); } try { typeManager.deleteModule(datasetModuleId); } catch (DatasetModuleConflictException e) { throw new DatasetModuleCannotBeDeletedException(datasetModuleId, e.getMessage()); } }
/** * Adds a new dataset module. * * @param module the new dataset module * @param className name of the dataset module class within the moduleJarFile * @param moduleJarFile Jar file containing the dataset module class and dependencies * @throws BadRequestException if the moduleJarFile does not exist * @throws AlreadyExistsException if a dataset module with the same name already exists * @throws IOException if a network error occurred */ public void add(DatasetModuleId module, String className, File moduleJarFile) throws BadRequestException, AlreadyExistsException, IOException, UnauthenticatedException { URL url = config.resolveNamespacedURLV3(module.getParent(), String.format("data/modules/%s", module.getModule())); Map<String, String> headers = ImmutableMap.of("X-Class-Name", className); HttpRequest request = HttpRequest.put(url).addHeaders(headers).withBody(moduleJarFile).build(); HttpResponse response = restClient.upload(request, config.getAccessToken(), HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_CONFLICT); if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) { throw new BadRequestException(String.format("Module jar file does not exist: %s", moduleJarFile)); } else if (response.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) { throw new DatasetModuleAlreadyExistsException(module); } }
/** * Deletes the specified {@link DatasetModuleId} */ @Override public void delete(DatasetModuleId datasetModuleId) throws Exception { NamespaceId namespaceId = datasetModuleId.getParent(); if (NamespaceId.SYSTEM.equals(namespaceId)) { throw new UnsupportedOperationException( String.format("Cannot delete module '%s' from '%s' namespace.", datasetModuleId.getModule(), datasetModuleId.getNamespace())); } ensureNamespaceExists(namespaceId); DatasetModuleMeta moduleMeta = typeManager.getModule(datasetModuleId); if (moduleMeta == null) { throw new DatasetModuleNotFoundException(datasetModuleId); } try { typeManager.deleteModule(datasetModuleId); } catch (DatasetModuleConflictException e) { throw new DatasetModuleCannotBeDeletedException(datasetModuleId, e.getMessage()); } }
/** * Gets information about a dataset module. * * @param module the dataset module * @return {@link DatasetModuleMeta} of the dataset module * @throws DatasetModuleNotFoundException if the dataset module with the specified name was not found * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public DatasetModuleMeta get(DatasetModuleId module) throws DatasetModuleNotFoundException, IOException, UnauthenticatedException, UnauthorizedException { URL url = config.resolveNamespacedURLV3(module.getParent(), String.format("data/modules/%s", module.getModule())); HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new DatasetModuleNotFoundException(module); } return ObjectResponse.fromJsonBody(response, DatasetModuleMeta.class).getResponseObject(); } }
/** * Deletes a dataset module. * * @param module the dataset module to delete * @throws DatasetModuleCannotBeDeletedException if the dataset module cannot be deleted, * usually due to other dataset modules or dataset instances using the dataset module * @throws DatasetModuleNotFoundException if the dataset module with the specified name was not found * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public void delete(DatasetModuleId module) throws DatasetModuleCannotBeDeletedException, DatasetModuleNotFoundException, IOException, UnauthenticatedException, UnauthorizedException { URL url = config.resolveNamespacedURLV3(module.getParent(), String.format("data/modules/%s", module.getModule())); HttpResponse response = restClient.execute(HttpMethod.DELETE, url, config.getAccessToken(), HttpURLConnection.HTTP_CONFLICT, HttpURLConnection.HTTP_NOT_FOUND); if (response.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) { throw new DatasetModuleCannotBeDeletedException(module); } else if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new DatasetModuleNotFoundException(module); } }