Java Code Examples for org.apache.kylin.metadata.model.DataModelDesc#setProjectName()

The following examples show how to use org.apache.kylin.metadata.model.DataModelDesc#setProjectName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelController.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value = "/{modelName}/clone", method = { RequestMethod.PUT }, produces = { "application/json" })
@ResponseBody
public ModelRequest cloneModel(@PathVariable String modelName, @RequestBody ModelRequest modelRequest) {
    String project = StringUtils.trimToNull(modelRequest.getProject());
    DataModelManager metaManager = DataModelManager.getInstance(KylinConfig.getInstanceFromEnv());
    DataModelDesc modelDesc = metaManager.getDataModelDesc(modelName);
    String newModelName = modelRequest.getModelName();

    if (null == project) {
        throw new BadRequestException("Project name should not be empty.");
    }

    if (modelDesc == null || StringUtils.isEmpty(modelName)) {
        throw new NotFoundException("Model does not exist.");
    }

    if (!project.equals(modelDesc.getProject())) {
        throw new BadRequestException("Cloning model across projects is not supported.");
    }

    if (StringUtils.isEmpty(newModelName)) {
        throw new BadRequestException("New model name should not be empty.");
    }
    if (!ValidateUtil.isAlphanumericUnderscore(newModelName)) {
        throw new BadRequestException(String.format(Locale.ROOT,
                "Invalid model name %s, only letters, numbers and underscore supported.", newModelName));
    }

    DataModelDesc newModelDesc = DataModelDesc.getCopyOf(modelDesc);
    newModelDesc.setProjectName(project);
    newModelDesc.setName(newModelName);
    try {
        newModelDesc = modelService.createModelDesc(project, newModelDesc);

        //reload avoid shallow
        metaManager.reloadDataModel(newModelName);
    } catch (IOException e) {
        throw new InternalErrorException("failed to clone DataModelDesc", e);
    }

    modelRequest.setUuid(newModelDesc.getUuid());
    modelRequest.setSuccessful(true);
    return modelRequest;
}
 
Example 2
Source File: ModelController.java    From kylin with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value = "/{modelName}/clone", method = { RequestMethod.PUT }, produces = { "application/json" })
@ResponseBody
public ModelRequest cloneModel(@PathVariable String modelName, @RequestBody ModelRequest modelRequest) {
    String project = StringUtils.trimToNull(modelRequest.getProject());
    DataModelManager metaManager = DataModelManager.getInstance(KylinConfig.getInstanceFromEnv());
    DataModelDesc modelDesc = metaManager.getDataModelDesc(modelName);
    String newModelName = modelRequest.getModelName();

    if (null == project) {
        throw new BadRequestException("Project name should not be empty.");
    }

    if (modelDesc == null || StringUtils.isEmpty(modelName)) {
        throw new NotFoundException("Model does not exist.");
    }

    if (!project.equals(modelDesc.getProject())) {
        throw new BadRequestException("Cloning model across projects is not supported.");
    }

    if (StringUtils.isEmpty(newModelName)) {
        throw new BadRequestException("New model name should not be empty.");
    }
    if (!ValidateUtil.isAlphanumericUnderscore(newModelName)) {
        throw new BadRequestException(String.format(Locale.ROOT,
                "Invalid model name %s, only letters, numbers and underscore supported.", newModelName));
    }

    DataModelDesc newModelDesc = DataModelDesc.getCopyOf(modelDesc);
    newModelDesc.setProjectName(project);
    newModelDesc.setName(newModelName);
    try {
        newModelDesc = modelService.createModelDesc(project, newModelDesc);

        //reload avoid shallow
        metaManager.reloadDataModel(newModelName);
    } catch (IOException e) {
        throw new InternalErrorException("failed to clone DataModelDesc", e);
    }

    modelRequest.setUuid(newModelDesc.getUuid());
    modelRequest.setSuccessful(true);
    return modelRequest;
}