use of co.cask.cdap.data2.dataset2.ModuleConflictException in project cdap by caskdata.
the class DatasetModulesDeployer method loadAndDeployModule.
private void loadAndDeployModule(ClassLoader artifactClassLoader, String className, Location jarLocation, String moduleName, NamespaceId namespaceId) throws ClassNotFoundException, IllegalAccessException, InstantiationException, DatasetManagementException {
// note: using app class loader to load module class
@SuppressWarnings("unchecked") Class<Dataset> clazz = (Class<Dataset>) artifactClassLoader.loadClass(className);
try {
// note: we can deploy module or create module from Dataset class
// note: it seems dangerous to instantiate dataset module here, but this will be fine when we move deploy into
// isolated user's environment (e.g. separate yarn container)
DatasetModuleId moduleId = namespaceId.datasetModule(moduleName);
DatasetModule module;
if (DatasetModule.class.isAssignableFrom(clazz)) {
module = (DatasetModule) clazz.newInstance();
} else if (Dataset.class.isAssignableFrom(clazz)) {
if (systemDatasetFramework.hasSystemType(clazz.getName())) {
return;
}
DatasetTypeId typeId = namespaceId.datasetType(clazz.getName());
if (datasetFramework.hasType(typeId) && !allowDatasetUncheckedUpgrade) {
return;
}
module = new SingleTypeModule(clazz);
} else {
throw new IllegalArgumentException(String.format("Cannot use class %s to add dataset module: it must be of type DatasetModule or Dataset", clazz.getName()));
}
LOG.info("Adding module: {}", clazz.getName());
datasetFramework.addModule(moduleId, module, jarLocation);
} catch (ModuleConflictException e) {
LOG.info("Conflict while deploying module {}: {}", moduleName, e.getMessage());
throw e;
}
}
use of co.cask.cdap.data2.dataset2.ModuleConflictException in project cdap by caskdata.
the class DatasetServiceClient method addModule.
public void addModule(String moduleName, String className, Location jarLocation) throws DatasetManagementException {
HttpRequest.Builder requestBuilder = remoteClient.requestBuilder(HttpMethod.PUT, "modules/" + moduleName).addHeader("X-Class-Name", className).withBody(Locations.newInputSupplier(jarLocation));
HttpResponse response = doRequest(requestBuilder);
if (HttpResponseStatus.CONFLICT.getCode() == response.getResponseCode()) {
throw new ModuleConflictException(String.format("Failed to add module %s due to conflict, details: %s", moduleName, response));
}
if (HttpResponseStatus.OK.getCode() != response.getResponseCode()) {
throw new DatasetManagementException(String.format("Failed to add module %s, details: %s", moduleName, response));
}
}
Aggregations