Search in sources :

Example 1 with ModuleConflictException

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;
    }
}
Also used : DatasetModuleId(co.cask.cdap.proto.id.DatasetModuleId) DatasetTypeId(co.cask.cdap.proto.id.DatasetTypeId) ModuleConflictException(co.cask.cdap.data2.dataset2.ModuleConflictException) Dataset(co.cask.cdap.api.dataset.Dataset) SingleTypeModule(co.cask.cdap.data2.dataset2.SingleTypeModule) DatasetModule(co.cask.cdap.api.dataset.module.DatasetModule)

Example 2 with ModuleConflictException

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));
    }
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) ModuleConflictException(co.cask.cdap.data2.dataset2.ModuleConflictException) HttpResponse(co.cask.common.http.HttpResponse)

Aggregations

ModuleConflictException (co.cask.cdap.data2.dataset2.ModuleConflictException)2 Dataset (co.cask.cdap.api.dataset.Dataset)1 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)1 DatasetModule (co.cask.cdap.api.dataset.module.DatasetModule)1 SingleTypeModule (co.cask.cdap.data2.dataset2.SingleTypeModule)1 DatasetModuleId (co.cask.cdap.proto.id.DatasetModuleId)1 DatasetTypeId (co.cask.cdap.proto.id.DatasetTypeId)1 HttpRequest (co.cask.common.http.HttpRequest)1 HttpResponse (co.cask.common.http.HttpResponse)1