Java Code Examples for org.apache.kylin.rest.exception.InternalErrorException

The following examples show how to use org.apache.kylin.rest.exception.InternalErrorException. These examples are extracted from open source projects. 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 Project: kylin   Source File: TableController.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/{tables}/{project}", method = { RequestMethod.DELETE }, produces = { "application/json" })
@ResponseBody
public Map<String, String[]> unLoadHiveTables(@PathVariable String tables, @PathVariable String project) {
    Set<String> unLoadSuccess = Sets.newHashSet();
    Set<String> unLoadFail = Sets.newHashSet();
    Map<String, String[]> result = new HashMap<String, String[]>();
    try {
        for (String tableName : StringUtil.splitByComma(tables)) {
            tableACLService.deleteFromTableACLByTbl(project, tableName);
            if (tableService.unloadHiveTable(tableName, project)) {
                unLoadSuccess.add(tableName);
            } else {
                unLoadFail.add(tableName);
            }
        }
    } catch (Throwable e) {
        logger.error("Failed to unload Hive Table", e);
        throw new InternalErrorException(e.getLocalizedMessage(), e);
    }
    result.put("result.unload.success", (String[]) unLoadSuccess.toArray(new String[unLoadSuccess.size()]));
    result.put("result.unload.fail", (String[]) unLoadFail.toArray(new String[unLoadFail.size()]));
    return result;
}
 
Example 2
Source Project: kylin-on-parquet-v2   Source File: ProjectController.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "", method = { RequestMethod.POST }, produces = { "application/json" })
@ResponseBody
public ProjectInstance saveProject(@RequestBody ProjectRequest projectRequest) {
    ProjectInstance projectDesc = deserializeProjectDesc(projectRequest);

    if (StringUtils.isEmpty(projectDesc.getName())) {
        throw new InternalErrorException("A project name must be given to create a project");
    }

    if (!ValidateUtil.isAlphanumericUnderscore(projectDesc.getName())) {
        throw new BadRequestException(
                String.format(Locale.ROOT,
                        "Invalid Project name %s, only letters, numbers and underscore supported.",
                projectDesc.getName()));
    }

    ProjectInstance createdProj = null;
    try {
        createdProj = projectService.createProject(projectDesc);
    } catch (Exception e) {
        throw new InternalErrorException(e.getLocalizedMessage(), e);
    }

    return createdProj;
}
 
Example 3
Source Project: kylin-on-parquet-v2   Source File: CubeController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Force rebuild a cube's lookup table snapshot
 *
 * @throws IOException
 */
@RequestMapping(value = "/{cubeName}/refresh_lookup", method = { RequestMethod.PUT }, produces = {
        "application/json" })
@ResponseBody
public JobInstance rebuildLookupSnapshot(@PathVariable String cubeName,
        @RequestBody LookupSnapshotBuildRequest request) {
    try {
        final CubeManager cubeMgr = cubeService.getCubeManager();
        final CubeInstance cube = cubeMgr.getCube(cubeName);
        String submitter = SecurityContextHolder.getContext().getAuthentication().getName();
        return jobService.submitLookupSnapshotJob(cube, request.getLookupTableName(), request.getSegmentIDs(),
                submitter);
    } catch (IOException e) {
        logger.error(e.getLocalizedMessage(), e);
        throw new InternalErrorException(e.getLocalizedMessage(), e);
    }
}
 
Example 4
Source Project: kylin-on-parquet-v2   Source File: CubeController.java    License: 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 5
Source Project: kylin-on-parquet-v2   Source File: CubeController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Send a auto merge cube job
 *
 * @param cubeName Cube ID
 * @return JobInstance of merging cube
 */
@RequestMapping(value = "/{cubeName}/automerge", method = { RequestMethod.PUT })
@ResponseBody
public JobInstance autoMerge(@PathVariable String cubeName) {
    try {
        checkCubeExists(cubeName);

        CubeInstance cube = jobService.getCubeManager().getCube(cubeName);
        aclEvaluate.checkProjectAdminPermission(cube.getProject());

        String jobID = cubeService.mergeCubeSegment(cubeName);
        if (jobID == null) {
            throw new BadRequestException(String.format(Locale.ROOT,
                    "Cube: %s merging is not supported or no segments to merge", cubeName));
        }
        return jobService.getJobInstance(jobID);
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
        throw new InternalErrorException(e.getLocalizedMessage());
    }
}
 
Example 6
Source Project: kylin-on-parquet-v2   Source File: ModelController.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "", method = { RequestMethod.PUT }, produces = { "application/json" })
@ResponseBody
public ModelRequest updateModelDesc(@RequestBody ModelRequest modelRequest) throws JsonProcessingException {
    DataModelDesc modelDesc = deserializeDataModelDesc(modelRequest);
    if (modelDesc == null) {
        return modelRequest;
    }
    try {
        modelDesc = modelService.updateModelAndDesc(modelRequest.getProject(), modelDesc);
    } catch (AccessDeniedException accessDeniedException) {
        throw new ForbiddenException("You don't have right to update this model.");
    } catch (Exception e) {
        logger.error("Failed to deal with the request:" + e.getLocalizedMessage(), e);
        throw new InternalErrorException("Failed to deal with the request: " + e.getLocalizedMessage(), e);
    }

    if (modelDesc.getError().isEmpty()) {
        modelRequest.setSuccessful(true);
    } else {
        logger.warn("Model " + modelDesc.getName() + " fail to update because " + modelDesc.getError());
        updateRequest(modelRequest, false, omitMessage(modelDesc.getError()));
    }
    String descData = JsonUtil.writeValueAsIndentString(modelDesc);
    modelRequest.setModelDescData(descData);
    return modelRequest;
}
 
Example 7
Source Project: kylin   Source File: StreamingV2Controller.java    License: 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 Project: kylin-on-parquet-v2   Source File: StreamingV2Controller.java    License: 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 Project: kylin   Source File: StreamingController.java    License: 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 Project: kylin-on-parquet-v2   Source File: BasicController.java    License: Apache License 2.0 6 votes vote down vote up
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(Exception.class)
@ResponseBody
ErrorResponse handleError(HttpServletRequest req, Exception ex) {
    logger.error("", ex);

    Message msg = MsgPicker.getMsg();
    Throwable cause = ex;
    while (cause != null) {
        if (cause.getClass().getPackage().getName().startsWith("org.apache.hadoop.hbase")) {
            return new ErrorResponse(req.getRequestURL().toString(), new InternalErrorException(
                    String.format(Locale.ROOT, msg.getHBASE_FAIL(), ex.getMessage()), ex));
        }
        cause = cause.getCause();
    }

    return new ErrorResponse(req.getRequestURL().toString(), ex);
}
 
Example 11
Source Project: kylin   Source File: StreamingV2Controller.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/updateConfig", method = { RequestMethod.PUT })
@ResponseBody
public StreamingRequest updateStreamingConfig(@RequestBody StreamingRequest streamingRequest)
        throws JsonProcessingException {
    StreamingSourceConfig streamingSourceConfig = deserializeStreamingConfig(streamingRequest.getStreamingConfig());

    if (streamingSourceConfig == null) {
        return streamingRequest;
    }

    final String user = SecurityContextHolder.getContext().getAuthentication().getName();
    logger.info("{} try to updateStreamingConfig.", user);
    try {
        streamingSourceConfig = streamingService.updateStreamingConfig(streamingSourceConfig);
    } catch (AccessDeniedException accessDeniedException) {
        throw new ForbiddenException("You don't have right to update this StreamingSourceConfig.");
    } catch (Exception e) {
        logger.error("Failed to deal with the request:" + e.getLocalizedMessage(), e);
        throw new InternalErrorException("Failed to deal with the request: " + e.getLocalizedMessage());
    }
    streamingRequest.setSuccessful(true);

    return streamingRequest;
}
 
Example 12
Source Project: kylin   Source File: BasicController.java    License: Apache License 2.0 6 votes vote down vote up
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(Exception.class)
@ResponseBody
ErrorResponse handleError(HttpServletRequest req, Exception ex) {
    logger.error("", ex);

    Message msg = MsgPicker.getMsg();
    Throwable cause = ex;
    while (cause != null) {
        if (cause.getClass().getPackage().getName().startsWith("org.apache.hadoop.hbase")) {
            return new ErrorResponse(req.getRequestURL().toString(), new InternalErrorException(
                    String.format(Locale.ROOT, msg.getHBASE_FAIL(), ex.getMessage()), ex));
        }
        cause = cause.getCause();
    }

    return new ErrorResponse(req.getRequestURL().toString(), ex);
}
 
Example 13
Source Project: kylin   Source File: AclService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void deleteAcl(ObjectIdentity objectIdentity, boolean deleteChildren) throws ChildrenExistException {
    try (AutoLock l = lock.lockForWrite()) {
        List<ObjectIdentity> children = findChildren(objectIdentity);
        if (!deleteChildren && children.size() > 0) {
            Message msg = MsgPicker.getMsg();
            throw new BadRequestException(
                    String.format(Locale.ROOT, msg.getIDENTITY_EXIST_CHILDREN(), objectIdentity));
        }
        for (ObjectIdentity oid : children) {
            deleteAcl(oid, deleteChildren);
        }
        crud.delete(objID(objectIdentity));
        logger.debug("ACL of " + objectIdentity + " deleted successfully.");
    } catch (IOException e) {
        throw new InternalErrorException(e);
    }
}
 
Example 14
Source Project: kylin-on-parquet-v2   Source File: TableController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Regenerate table cardinality
 *
 * @return Table metadata array
 * @throws IOException
 */
@RequestMapping(value = "/{project}/{tableNames}/cardinality", method = { RequestMethod.PUT }, produces = {
        "application/json" })
@ResponseBody
public CardinalityRequest generateCardinality(@PathVariable String tableNames,
        @RequestBody CardinalityRequest request, @PathVariable String project) throws Exception {
    String submitter = SecurityContextHolder.getContext().getAuthentication().getName();
    String[] tables = StringUtil.splitByComma(tableNames);
    try {
        for (String table : tables) {
            tableService.calculateCardinality(table.trim().toUpperCase(Locale.ROOT), submitter, project);
        }
    } catch (IOException e) {
        logger.error("Failed to calculate cardinality", e);
        throw new InternalErrorException(e.getLocalizedMessage(), e);
    }
    return request;
}
 
Example 15
Source Project: kylin-on-parquet-v2   Source File: StreamingController.java    License: 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 16
Source Project: kylin   Source File: TableController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Regenerate table cardinality
 *
 * @return Table metadata array
 * @throws IOException
 */
@RequestMapping(value = "/{project}/{tableNames}/cardinality", method = { RequestMethod.PUT }, produces = {
        "application/json" })
@ResponseBody
public CardinalityRequest generateCardinality(@PathVariable String tableNames,
        @RequestBody CardinalityRequest request, @PathVariable String project) throws Exception {
    String submitter = SecurityContextHolder.getContext().getAuthentication().getName();
    String[] tables = StringUtil.splitByComma(tableNames);
    try {
        for (String table : tables) {
            tableService.calculateCardinality(table.trim().toUpperCase(Locale.ROOT), submitter, project);
        }
    } catch (IOException e) {
        logger.error("Failed to calculate cardinality", e);
        throw new InternalErrorException(e.getLocalizedMessage(), e);
    }
    return request;
}
 
Example 17
Source Project: kylin-on-parquet-v2   Source File: JobController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Pause a job
 *
 * @return
 * @throws IOException
 */
@RequestMapping(value = "/{jobId}/pause", method = { RequestMethod.PUT }, produces = { "application/json" })
@ResponseBody
public JobInstance pause(@PathVariable String jobId) {

    try {
        final JobInstance jobInstance = jobService.getJobInstance(jobId);
        if (jobInstance == null) {
            throw new BadRequestException("Cannot find job: " + jobId);
        }
        jobService.pauseJob(jobInstance);
        return jobService.getJobInstance(jobId);
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
        throw new InternalErrorException(e);
    }

}
 
Example 18
Source Project: kylin-on-parquet-v2   Source File: JobController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Rollback a job to the given step
 *
 * @return
 * @throws IOException
 */
@RequestMapping(value = "/{jobId}/steps/{stepId}/rollback", method = { RequestMethod.PUT }, produces = {
        "application/json" })
@ResponseBody
public JobInstance rollback(@PathVariable String jobId, @PathVariable String stepId) {
    try {
        final JobInstance jobInstance = jobService.getJobInstance(jobId);
        if (jobInstance == null) {
            throw new BadRequestException("Cannot find job: " + jobId);
        }
        jobService.rollbackJob(jobInstance, stepId);
        return jobService.getJobInstance(jobId);
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
        throw new InternalErrorException(e);
    }
}
 
Example 19
Source Project: kylin-on-parquet-v2   Source File: JobController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Drop a cube job
 *
 * @return
 * @throws IOException
 */
@RequestMapping(value = "/{jobId}/drop", method = { RequestMethod.DELETE }, produces = { "application/json" })
@ResponseBody
public JobInstance dropJob(@PathVariable String jobId) {
    JobInstance jobInstance = null;
    try {
        jobInstance = jobService.getJobInstance(jobId);
        if (jobInstance == null) {
            throw new BadRequestException("Cannot find job: " + jobId);
        }
        jobService.dropJob(jobInstance);
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
        throw new InternalErrorException(e);
    }

    return jobInstance;
}
 
Example 20
Source Project: kylin-on-parquet-v2   Source File: AclService.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void deleteAcl(ObjectIdentity objectIdentity, boolean deleteChildren) throws ChildrenExistException {
    try (AutoLock l = lock.lockForWrite()) {
        List<ObjectIdentity> children = findChildren(objectIdentity);
        if (!deleteChildren && children.size() > 0) {
            Message msg = MsgPicker.getMsg();
            throw new BadRequestException(
                    String.format(Locale.ROOT, msg.getIDENTITY_EXIST_CHILDREN(), objectIdentity));
        }
        for (ObjectIdentity oid : children) {
            deleteAcl(oid, deleteChildren);
        }
        crud.delete(objID(objectIdentity));
        logger.debug("ACL of " + objectIdentity + " deleted successfully.");
    } catch (IOException e) {
        throw new InternalErrorException(e);
    }
}
 
Example 21
Source Project: kylin-on-parquet-v2   Source File: AclService.java    License: Apache License 2.0 6 votes vote down vote up
private MutableAclRecord updateAclWithRetry(MutableAclRecord acl, AclRecordUpdater updater) {
    int retry = 7;
    while (retry-- > 0) {
        AclRecord record = acl.getAclRecord();

        updater.update(record);
        try {
            crud.save(record);
            return acl; // here we are done

        } catch (WriteConflictException ise) {
            if (retry <= 0) {
                logger.error("Retry is out, till got error, abandoning...", ise);
                throw ise;
            }

            logger.warn("Write conflict to update ACL " + resourceKey(record.getObjectIdentity())
                    + " retry remaining " + retry + ", will retry...");
            acl = readAcl(acl.getObjectIdentity());

        } catch (IOException e) {
            throw new InternalErrorException(e);
        }
    }
    throw new RuntimeException("should not reach here");
}
 
Example 22
Source Project: kylin   Source File: BaseControllerTest.java    License: 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 23
Source Project: kylin   Source File: MigrationRuleSet.java    License: Apache License 2.0 6 votes vote down vote up
public Context(QueryService queryService, CubeInstance cubeInstance, String targetHost, String tgtProjectName) {
    this.queryService = queryService;
    this.cubeInstance = cubeInstance;
    this.targetAddress = targetHost;
    KylinConfig targetConfig = KylinConfig.createInstanceFromUri(targetHost);
    this.targetResourceStore = ResourceStore.getStore(targetConfig);
    this.tgtProjectName = tgtProjectName;

    List<ProjectInstance> projList = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv())
            .findProjects(cubeInstance.getType(), cubeInstance.getName());
    if (projList.size() != 1) {
        throw new InternalErrorException("Cube " + cubeInstance.getName()
                + " should belong to only one project. However, it's belong to " + projList);
    }
    this.srcProjectName = projList.get(0).getName();
}
 
Example 24
Source Project: kylin   Source File: ProjectController.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "", method = { RequestMethod.POST }, produces = { "application/json" })
@ResponseBody
public ProjectInstance saveProject(@RequestBody ProjectRequest projectRequest) {
    ProjectInstance projectDesc = deserializeProjectDesc(projectRequest);

    if (StringUtils.isEmpty(projectDesc.getName())) {
        throw new InternalErrorException("A project name must be given to create a project");
    }

    if (!ValidateUtil.isAlphanumericUnderscore(projectDesc.getName())) {
        throw new BadRequestException(
                String.format(Locale.ROOT,
                        "Invalid Project name %s, only letters, numbers and underscore supported.",
                projectDesc.getName()));
    }

    ProjectInstance createdProj = null;
    try {
        createdProj = projectService.createProject(projectDesc);
    } catch (Exception e) {
        throw new InternalErrorException(e.getLocalizedMessage(), e);
    }

    return createdProj;
}
 
Example 25
Source Project: kylin   Source File: CubeController.java    License: 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 26
Source Project: kylin-on-parquet-v2   Source File: ProjectControllerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = InternalErrorException.class)
public void testAddExistingProject() throws IOException {
    ProjectInstance newProject = new ProjectInstance();
    newProject.setName("default");

    projectController.saveProject(getProjectRequest(newProject, null));
}
 
Example 27
Source Project: kylin-on-parquet-v2   Source File: CubeControllerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = InternalErrorException.class)
public void testDeleteSegmentNew() throws IOException {
    String cubeName = "test_kylin_cube_with_slr_ready_3_segments";
    CubeDesc[] cubes = cubeDescController.getCube(cubeName);
    Assert.assertNotNull(cubes);

    String segmentName = "20131212000000_20140112000000";

    CubeInstance cube = cubeService.getCubeManager().getCube(cubeName);
    cubeController.disableCube(cubeName);

    CubeSegment toDelete = null;
    for (CubeSegment seg : cube.getSegments()) {
        if (seg.getName().equals(segmentName)) {
            toDelete = seg;
            break;
        }
    }

    Assert.assertNotNull(toDelete);
    String segId = toDelete.getUuid();

    cubeController.deleteSegment(cubeName, segmentName);

    // delete success, no related job 'NEW' segment can be delete
    if (cubeService.isOrphonSegment(cube, segId)){
        throw new InternalErrorException();
    }
    cubeController.enableCube(cubeName);
}
 
Example 28
Source Project: kylin-on-parquet-v2   Source File: UserServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteAdmin() throws IOException {
    try {
        userService.deleteUser("ADMIN");
        throw new InternalErrorException();
    } catch (InternalErrorException e) {
        Assert.assertEquals(e.getMessage(), "User ADMIN is not allowed to be deleted.");
    }

}
 
Example 29
Source Project: kylin   Source File: BasicController.java    License: Apache License 2.0 5 votes vote down vote up
protected void setDownloadResponse(String downloadFile, final HttpServletResponse response) {
    File file = new File(downloadFile);
    try (InputStream fileInputStream = new FileInputStream(file);
            OutputStream output = response.getOutputStream()) {
        response.reset();
        response.setContentType("application/octet-stream");
        response.setContentLength((int) (file.length()));
        response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getName() + "\"");
        IOUtils.copyLarge(fileInputStream, output);
        output.flush();
    } catch (IOException e) {
        throw new InternalErrorException("Failed to download file: " + e.getMessage(), e);
    }
}
 
Example 30
Source Project: kylin-on-parquet-v2   Source File: ProjectController.java    License: Apache License 2.0 5 votes vote down vote up
private ProjectInstance deserializeProjectDesc(ProjectRequest projectRequest) {
    ProjectInstance projectDesc = null;
    try {
        logger.debug("Saving project " + projectRequest.getProjectDescData());
        projectDesc = JsonUtil.readValue(projectRequest.getProjectDescData(), ProjectInstance.class);
    } catch (Exception e) {
        logger.error("Failed to deal with the request.", e);
        throw new InternalErrorException("Failed to deal with the request:" + e.getMessage(), e);
    }
    return projectDesc;
}