org.apache.kylin.rest.exception.NotFoundException Java Examples

The following examples show how to use org.apache.kylin.rest.exception.NotFoundException. 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: BaseControllerTest.java    From Kylin with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasics() throws IOException {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("http://localhost");

    NotFoundException notFoundException = new NotFoundException("not found");
    ErrorResponse errorResponse = basicController.handleBadRequest(request, notFoundException);
    Assert.assertNotNull(errorResponse);

    ForbiddenException forbiddenException = new ForbiddenException("forbidden");
    errorResponse = basicController.handleForbidden(request, forbiddenException);
    Assert.assertNotNull(errorResponse);

    InternalErrorException internalErrorException = new InternalErrorException("error");
    errorResponse = basicController.handleError(request, internalErrorException);
    Assert.assertNotNull(errorResponse);

    BadRequestException badRequestException = new BadRequestException("error");
    errorResponse = basicController.handleBadRequest(request, badRequestException);
    Assert.assertNotNull(errorResponse);
}
 
Example #2
Source File: CubeController.java    From kylin with Apache License 2.0 6 votes vote down vote up
/**
 * Get SQL of a Cube segment
 *
 * @param cubeName    Cube Name
 * @param segmentName Segment Name
 * @return
 * @throws IOException
 */
@RequestMapping(value = "/{cubeName}/segs/{segmentName}/sql", method = { RequestMethod.GET }, produces = {
        "application/json" })
@ResponseBody
public GeneralResponse getSql(@PathVariable String cubeName, @PathVariable String segmentName) {

    checkCubeExists(cubeName);
    CubeInstance cube = cubeService.getCubeManager().getCube(cubeName);

    CubeSegment segment = cube.getSegment(segmentName, null);
    if (segment == null) {
        throw new NotFoundException("Cannot find segment " + segmentName);
    }

    IJoinedFlatTableDesc flatTableDesc = new CubeJoinedFlatTableDesc(segment, true);
    String sql = JoinedFlatTable.generateSelectDataStatement(flatTableDesc);

    GeneralResponse response = new GeneralResponse();
    response.setProperty("sql", sql);

    return response;
}
 
Example #3
Source File: BaseControllerTest.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasics() throws IOException {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("http://localhost");

    NotFoundException notFoundException = new NotFoundException("not found");
    ErrorResponse errorResponse = basicController.handleBadRequest(request, notFoundException);
    Assert.assertNotNull(errorResponse);

    ForbiddenException forbiddenException = new ForbiddenException("forbidden");
    errorResponse = basicController.handleForbidden(request, forbiddenException);
    Assert.assertNotNull(errorResponse);

    InternalErrorException internalErrorException = new InternalErrorException("error");
    errorResponse = basicController.handleError(request, internalErrorException);
    Assert.assertNotNull(errorResponse);

    BadRequestException badRequestException = new BadRequestException("error");
    errorResponse = basicController.handleBadRequest(request, badRequestException);
    Assert.assertNotNull(errorResponse);
}
 
Example #4
Source File: BaseControllerTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasics() throws IOException {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("http://localhost");

    NotFoundException notFoundException = new NotFoundException("not found");
    ErrorResponse errorResponse = basicController.handleBadRequest(request, notFoundException);
    Assert.assertNotNull(errorResponse);

    ForbiddenException forbiddenException = new ForbiddenException("forbidden");
    errorResponse = basicController.handleForbidden(request, forbiddenException);
    Assert.assertNotNull(errorResponse);

    InternalErrorException internalErrorException = new InternalErrorException("error");
    errorResponse = basicController.handleError(request, internalErrorException);
    Assert.assertNotNull(errorResponse);

    BadRequestException badRequestException = new BadRequestException("error");
    errorResponse = basicController.handleBadRequest(request, badRequestException);
    Assert.assertNotNull(errorResponse);
}
 
Example #5
Source File: StreamingController.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/{project}/{configName}", method = { RequestMethod.DELETE }, produces = {
        "application/json" })
@ResponseBody
public void deleteConfig(@PathVariable String project, @PathVariable String configName) throws IOException {
    StreamingConfig config = streamingService.getStreamingManager().getStreamingConfig(configName);
    KafkaConfig kafkaConfig = kafkaConfigService.getKafkaConfig(configName, project);
    if (null == config) {
        throw new NotFoundException("StreamingConfig with name " + configName + " not found..");
    }
    try {
        streamingService.dropStreamingConfig(config, project);
        kafkaConfigService.dropKafkaConfig(kafkaConfig, project);
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
        throw new InternalErrorException("Failed to delete StreamingConfig. " + " Caused by: " + e.getMessage(), e);
    }
}
 
Example #6
Source File: CubeController.java    From kylin with Apache License 2.0 6 votes vote down vote up
/**
 * Delete a cube segment
 *
 * @throws IOException
 */
@RequestMapping(value = "/{cubeName}/segs/{segmentName}", method = { RequestMethod.DELETE }, produces = {
        "application/json" })
@ResponseBody
public CubeInstance deleteSegment(@PathVariable String cubeName, @PathVariable String segmentName) {
    checkCubeExists(cubeName);
    CubeInstance cube = cubeService.getCubeManager().getCube(cubeName);

    CubeSegment segment = cube.getSegment(segmentName, null);
    if (segment == null) {
        throw new NotFoundException("Cannot find segment '" + segmentName + "'");
    }

    try {
        return cubeService.deleteSegment(cube, segmentName);
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
        throw new InternalErrorException(e.getLocalizedMessage(), e);
    }
}
 
Example #7
Source File: StreamingV2Controller.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/{configName}", method = { RequestMethod.DELETE })
@ResponseBody
public void deleteConfig(@PathVariable String configName) throws IOException {
    StreamingSourceConfig config = streamingService.getStreamingManagerV2().getConfig(configName);
    if (null == config) {
        throw new NotFoundException("StreamingSourceConfig with name " + configName + " not found..");
    }

    final String user = SecurityContextHolder.getContext().getAuthentication().getName();
    logger.info("{} try to delete config: {}", user, configName);

    try {
        streamingService.dropStreamingConfig(config);
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
        throw new InternalErrorException(
                "Failed to delete StreamingSourceConfig. " + " Caused by: " + e.getMessage(), e);
    }
}
 
Example #8
Source File: StreamingV2Controller.java    From kylin with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/{configName}", method = { RequestMethod.DELETE })
@ResponseBody
public void deleteConfig(@PathVariable String configName) throws IOException {
    StreamingSourceConfig config = streamingService.getStreamingManagerV2().getConfig(configName);
    if (null == config) {
        throw new NotFoundException("StreamingSourceConfig with name " + configName + " not found..");
    }

    final String user = SecurityContextHolder.getContext().getAuthentication().getName();
    logger.info("{} try to delete config: {}", user, configName);

    try {
        streamingService.dropStreamingConfig(config);
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
        throw new InternalErrorException(
                "Failed to delete StreamingSourceConfig. " + " Caused by: " + e.getMessage(), e);
    }
}
 
Example #9
Source File: StreamingController.java    From kylin with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/{project}/{configName}", method = { RequestMethod.DELETE }, produces = {
        "application/json" })
@ResponseBody
public void deleteConfig(@PathVariable String project, @PathVariable String configName) throws IOException {
    StreamingConfig config = streamingService.getStreamingManager().getStreamingConfig(configName);
    KafkaConfig kafkaConfig = kafkaConfigService.getKafkaConfig(configName, project);
    if (null == config) {
        throw new NotFoundException("StreamingConfig with name " + configName + " not found..");
    }
    try {
        streamingService.dropStreamingConfig(config, project);
        kafkaConfigService.dropKafkaConfig(kafkaConfig, project);
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
        throw new InternalErrorException("Failed to delete StreamingConfig. " + " Caused by: " + e.getMessage(), e);
    }
}
 
Example #10
Source File: CubeController.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
/**
 * Delete a cube segment
 *
 * @throws IOException
 */
@RequestMapping(value = "/{cubeName}/segs/{segmentName}", method = { RequestMethod.DELETE }, produces = {
        "application/json" })
@ResponseBody
public CubeInstance deleteSegment(@PathVariable String cubeName, @PathVariable String segmentName) {
    checkCubeExists(cubeName);
    CubeInstance cube = cubeService.getCubeManager().getCube(cubeName);

    CubeSegment segment = cube.getSegment(segmentName, null);
    if (segment == null) {
        throw new NotFoundException("Cannot find segment '" + segmentName + "'");
    }

    try {
        return cubeService.deleteSegment(cube, segmentName);
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
        throw new InternalErrorException(e.getLocalizedMessage(), e);
    }
}
 
Example #11
Source File: CubeController.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
/**
 * Get SQL of a Cube segment
 *
 * @param cubeName    Cube Name
 * @param segmentName Segment Name
 * @return
 * @throws IOException
 */
@RequestMapping(value = "/{cubeName}/segs/{segmentName}/sql", method = { RequestMethod.GET }, produces = {
        "application/json" })
@ResponseBody
public GeneralResponse getSql(@PathVariable String cubeName, @PathVariable String segmentName) {

    checkCubeExists(cubeName);
    CubeInstance cube = cubeService.getCubeManager().getCube(cubeName);

    CubeSegment segment = cube.getSegment(segmentName, null);
    if (segment == null) {
        throw new NotFoundException("Cannot find segment " + segmentName);
    }

    IJoinedFlatTableDesc flatTableDesc = new CubeJoinedFlatTableDesc(segment, true);
    String sql = JoinedFlatTable.generateSelectDataStatement(flatTableDesc);

    GeneralResponse response = new GeneralResponse();
    response.setProperty("sql", sql);

    return response;
}
 
Example #12
Source File: CubeController.java    From Kylin with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/{cubeName}", method = {RequestMethod.DELETE})
@ResponseBody
@Metered(name = "deleteCube")
public void deleteCube(@PathVariable String cubeName) {
    CubeInstance cube = cubeService.getCubeManager().getCube(cubeName);
    if (null == cube) {
        throw new NotFoundException("Cube with name " + cubeName + " not found..");
    }

    try {
        cubeService.deleteCube(cube);
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
        throw new InternalErrorException("Failed to delete cube. " + " Caused by: " + e.getMessage(), e);
    }
}
 
Example #13
Source File: ModelController.java    From kylin with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/{modelName}", method = { RequestMethod.DELETE }, produces = { "application/json" })
@ResponseBody
public void deleteModel(@PathVariable String modelName) {
    DataModelDesc desc = modelService.getDataModelManager().getDataModelDesc(modelName);
    if (null == desc) {
        throw new NotFoundException("Data Model with name " + modelName + " not found..");
    }
    try {
        modelService.dropModel(desc);
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
        throw new InternalErrorException("Failed to delete model. " + " Caused by: " + e.getMessage(), e);
    }
}
 
Example #14
Source File: CubeController.java    From kylin with Apache License 2.0 5 votes vote down vote up
private void checkCubeExists(String cubeName) {
    CubeInstance cubeInstance = cubeService.getCubeManager().getCube(cubeName);
    if (cubeInstance == null) {
        Message msg = MsgPicker.getMsg();
        throw new NotFoundException(String.format(Locale.ROOT, msg.getCUBE_NOT_FOUND(), cubeName));
    }
}
 
Example #15
Source File: TableController.java    From kylin with Apache License 2.0 5 votes vote down vote up
/**
 * Get available table list of the input database
 *
 * @return Table metadata array
 * @throws IOException
 */
@RequestMapping(value = "/{project}/{tableName:.+}", method = { RequestMethod.GET }, produces = {
        "application/json" })
@ResponseBody
public TableDesc getTableDesc(@PathVariable String tableName, @PathVariable String project) {
    TableDesc table = tableService.getTableDescByName(tableName, false, project);
    if (table == null)
        throw new NotFoundException("Could not find Hive table: " + tableName);
    return table;
}
 
Example #16
Source File: CubeController.java    From kylin with Apache License 2.0 5 votes vote down vote up
/**
 * save cubeDesc
 *
 * @return Table metadata array
 * @throws IOException
 */
@RequestMapping(value = "", method = { RequestMethod.POST }, produces = { "application/json" })
@ResponseBody
public CubeRequest saveCubeDesc(@RequestBody CubeRequest cubeRequest) {

    CubeDesc desc = deserializeCubeDesc(cubeRequest);

    if (desc == null) {
        cubeRequest.setMessage("CubeDesc is null.");
        return cubeRequest;
    }
    String name = desc.getName();
    if (StringUtils.isEmpty(name)) {
        logger.info("Cube name should not be empty.");
        throw new BadRequestException("Cube name should not be empty.");
    }
    if (!ValidateUtil.isAlphanumericUnderscore(name)) {
        throw new BadRequestException("Invalid Cube name, only letters, numbers and underscore supported.");
    }

    validateColumnFamily(desc);

    try {
        desc.setUuid(RandomUtil.randomUUID().toString());
        String projectName = (null == cubeRequest.getProject()) ? ProjectInstance.DEFAULT_PROJECT_NAME
                : cubeRequest.getProject();
        ProjectInstance project = cubeService.getProjectManager().getProject(projectName);
        if (project == null) {
            throw new NotFoundException("Project " + projectName + " doesn't exist");
        }
        cubeService.createCubeAndDesc(project, desc);
    } catch (Exception e) {
        logger.error("Failed to deal with the request.", e);
        throw new InternalErrorException(e.getLocalizedMessage(), e);
    }

    cubeRequest.setUuid(desc.getUuid());
    cubeRequest.setSuccessful(true);
    return cubeRequest;
}
 
Example #17
Source File: CubeControllerTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test(expected = NotFoundException.class)
public void testDeleteSegmentNotExist() throws IOException {
    String cubeName = "test_kylin_cube_with_slr_ready_3_segments";
    CubeDesc[] cubes = cubeDescController.getCube(cubeName);
    Assert.assertNotNull(cubes);

    cubeController.disableCube(cubeName);

    cubeController.deleteSegment(cubeName, "not_exist_segment");

    cubeController.enableCube(cubeName);
}
 
Example #18
Source File: ProjectController.java    From kylin with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "", method = { RequestMethod.PUT }, produces = { "application/json" })
@ResponseBody
public ProjectInstance updateProject(@RequestBody ProjectRequest projectRequest) {
    String formerProjectName = projectRequest.getFormerProjectName();
    if (StringUtils.isEmpty(formerProjectName)) {
        throw new InternalErrorException("A project name must be given to update a project");
    }

    ProjectInstance projectDesc = deserializeProjectDesc(projectRequest);

    ProjectInstance updatedProj = null;
    try {
        ProjectInstance currentProject = projectService.getProjectManager().getProject(formerProjectName);
        if (currentProject == null) {
            throw new NotFoundException("The project named " + formerProjectName + " does not exists");
        }

        if (projectDesc.getName().equals(currentProject.getName())) {
            updatedProj = projectService.updateProject(projectDesc, currentProject);
        } else {
            throw new IllegalStateException("Rename project is not supported yet, from " + formerProjectName
                    + " to " + projectDesc.getName());
        }
    } catch (Exception e) {
        logger.error("Failed to deal with the request.", e);
        throw new InternalErrorException(e.getLocalizedMessage(), e);
    }

    return updatedProj;
}
 
Example #19
Source File: TableController.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Get available table list of the input database
 *
 * @return Table metadata array
 * @throws IOException
 */
@RequestMapping(value = "/{project}/{tableName:.+}", method = { RequestMethod.GET }, produces = {
        "application/json" })
@ResponseBody
public TableDesc getTableDesc(@PathVariable String tableName, @PathVariable String project) {
    TableDesc table = tableService.getTableDescByName(tableName, false, project);
    if (table == null)
        throw new NotFoundException("Could not find Hive table: " + tableName);
    return table;
}
 
Example #20
Source File: ModelController.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/{modelName}", method = { RequestMethod.DELETE }, produces = { "application/json" })
@ResponseBody
public void deleteModel(@PathVariable String modelName) {
    DataModelDesc desc = modelService.getDataModelManager().getDataModelDesc(modelName);
    if (null == desc) {
        throw new NotFoundException("Data Model with name " + modelName + " not found..");
    }
    try {
        modelService.dropModel(desc);
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
        throw new InternalErrorException("Failed to delete model. " + " Caused by: " + e.getMessage(), e);
    }
}
 
Example #21
Source File: CubeController.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private void checkCubeExists(String cubeName) {
    CubeInstance cubeInstance = cubeService.getCubeManager().getCube(cubeName);
    if (cubeInstance == null) {
        Message msg = MsgPicker.getMsg();
        throw new NotFoundException(String.format(Locale.ROOT, msg.getCUBE_NOT_FOUND(), cubeName));
    }
}
 
Example #22
Source File: CubeController.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * save cubeDesc
 *
 * @return Table metadata array
 * @throws IOException
 */
@RequestMapping(value = "", method = { RequestMethod.POST }, produces = { "application/json" })
@ResponseBody
public CubeRequest saveCubeDesc(@RequestBody CubeRequest cubeRequest) {

    CubeDesc desc = deserializeCubeDesc(cubeRequest);

    if (desc == null) {
        cubeRequest.setMessage("CubeDesc is null.");
        return cubeRequest;
    }
    String name = desc.getName();
    if (StringUtils.isEmpty(name)) {
        logger.info("Cube name should not be empty.");
        throw new BadRequestException("Cube name should not be empty.");
    }
    if (!ValidateUtil.isAlphanumericUnderscore(name)) {
        throw new BadRequestException("Invalid Cube name, only letters, numbers and underscore supported.");
    }

    validateColumnFamily(desc);

    try {
        desc.setUuid(RandomUtil.randomUUID().toString());
        String projectName = (null == cubeRequest.getProject()) ? ProjectInstance.DEFAULT_PROJECT_NAME
                : cubeRequest.getProject();
        ProjectInstance project = cubeService.getProjectManager().getProject(projectName);
        if (project == null) {
            throw new NotFoundException("Project " + projectName + " doesn't exist");
        }
        cubeService.createCubeAndDesc(project, desc);
    } catch (Exception e) {
        logger.error("Failed to deal with the request.", e);
        throw new InternalErrorException(e.getLocalizedMessage(), e);
    }

    cubeRequest.setUuid(desc.getUuid());
    cubeRequest.setSuccessful(true);
    return cubeRequest;
}
 
Example #23
Source File: ProjectController.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "", method = { RequestMethod.PUT }, produces = { "application/json" })
@ResponseBody
public ProjectInstance updateProject(@RequestBody ProjectRequest projectRequest) {
    String formerProjectName = projectRequest.getFormerProjectName();
    if (StringUtils.isEmpty(formerProjectName)) {
        throw new InternalErrorException("A project name must be given to update a project");
    }

    ProjectInstance projectDesc = deserializeProjectDesc(projectRequest);

    ProjectInstance updatedProj = null;
    try {
        ProjectInstance currentProject = projectService.getProjectManager().getProject(formerProjectName);
        if (currentProject == null) {
            throw new NotFoundException("The project named " + formerProjectName + " does not exists");
        }

        if (projectDesc.getName().equals(currentProject.getName())) {
            updatedProj = projectService.updateProject(projectDesc, currentProject);
        } else {
            throw new IllegalStateException("Rename project is not supported yet, from " + formerProjectName
                    + " to " + projectDesc.getName());
        }
    } catch (Exception e) {
        logger.error("Failed to deal with the request.", e);
        throw new InternalErrorException(e.getLocalizedMessage(), e);
    }

    return updatedProj;
}
 
Example #24
Source File: CubeControllerTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Test(expected = NotFoundException.class)
public void testDeleteSegmentNotExist() throws IOException {
    String cubeName = "test_kylin_cube_with_slr_ready_3_segments";
    CubeDesc[] cubes = cubeDescController.getCube(cubeName);
    Assert.assertNotNull(cubes);

    cubeController.disableCube(cubeName);

    cubeController.deleteSegment(cubeName, "not_exist_segment");

    cubeController.enableCube(cubeName);
}
 
Example #25
Source File: CubeController.java    From kylin with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value = "/{cubeName}/clone", method = { RequestMethod.PUT }, produces = { "application/json" })
@ResponseBody
public CubeInstance cloneCube(@PathVariable String cubeName, @RequestBody CubeRequest cubeRequest) {
    String newCubeName = cubeRequest.getCubeName();
    String projectName = cubeRequest.getProject();

    checkCubeExists(cubeName);
    CubeInstance cube = cubeService.getCubeManager().getCube(cubeName);
    if (cube.getStatus() == RealizationStatusEnum.DESCBROKEN) {
        throw new BadRequestException("Broken cube can't be cloned");
    }
    if (!ValidateUtil.isAlphanumericUnderscore(newCubeName)) {
        throw new BadRequestException("Invalid Cube name, only letters, numbers and underscore supported.");
    }

    ProjectInstance project = cubeService.getProjectManager().getProject(projectName);
    if (project == null) {
        throw new NotFoundException("Project " + projectName + " doesn't exist");
    }
    // KYLIN-1925, forbid cloning cross projects
    if (!project.getName().equals(cube.getProject())) {
        throw new BadRequestException("Cloning cubes across projects is not supported.");
    }

    CubeDesc cubeDesc = cube.getDescriptor();
    CubeDesc newCubeDesc = CubeDesc.getCopyOf(cubeDesc);

    newCubeDesc.setName(newCubeName);

    CubeInstance newCube;
    try {
        newCube = cubeService.createCubeAndDesc(project, newCubeDesc);

        //reload to avoid shallow clone
        cubeService.getCubeDescManager().reloadCubeDescLocal(newCubeName);
    } catch (IOException e) {
        throw new InternalErrorException("Failed to clone cube ", e);
    }

    return newCube;

}
 
Example #26
Source File: BasicController.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(NotFoundException.class)
@ResponseBody
ErrorResponse handleNotFound(HttpServletRequest req, Exception ex) {
    return new ErrorResponse(req.getRequestURL().toString(), ex);
}
 
Example #27
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 #28
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;
}
 
Example #29
Source File: BasicController.java    From kylin with Apache License 2.0 4 votes vote down vote up
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(NotFoundException.class)
@ResponseBody
ErrorResponse handleNotFound(HttpServletRequest req, Exception ex) {
    return new ErrorResponse(req.getRequestURL().toString(), ex);
}
 
Example #30
Source File: CubeController.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value = "/{cubeName}/clone", method = { RequestMethod.PUT }, produces = { "application/json" })
@ResponseBody
public CubeInstance cloneCube(@PathVariable String cubeName, @RequestBody CubeRequest cubeRequest) {
    String newCubeName = cubeRequest.getCubeName();
    String projectName = cubeRequest.getProject();

    checkCubeExists(cubeName);
    CubeInstance cube = cubeService.getCubeManager().getCube(cubeName);
    if (cube.getStatus() == RealizationStatusEnum.DESCBROKEN) {
        throw new BadRequestException("Broken cube can't be cloned");
    }
    if (!ValidateUtil.isAlphanumericUnderscore(newCubeName)) {
        throw new BadRequestException("Invalid Cube name, only letters, numbers and underscore supported.");
    }

    ProjectInstance project = cubeService.getProjectManager().getProject(projectName);
    if (project == null) {
        throw new NotFoundException("Project " + projectName + " doesn't exist");
    }
    // KYLIN-1925, forbid cloning cross projects
    if (!project.getName().equals(cube.getProject())) {
        throw new BadRequestException("Cloning cubes across projects is not supported.");
    }

    CubeDesc cubeDesc = cube.getDescriptor();
    CubeDesc newCubeDesc = CubeDesc.getCopyOf(cubeDesc);

    newCubeDesc.setName(newCubeName);

    CubeInstance newCube;
    try {
        newCube = cubeService.createCubeAndDesc(project, newCubeDesc);

        //reload to avoid shallow clone
        cubeService.getCubeDescManager().reloadCubeDescLocal(newCubeName);
    } catch (IOException e) {
        throw new InternalErrorException("Failed to clone cube ", e);
    }

    return newCube;

}