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

The following examples show how to use org.apache.kylin.rest.exception.BadRequestException. 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: DiagnosisService.java    From kylin with Apache License 2.0 6 votes vote down vote up
private void runDiagnosisCLI(String[] args) throws IOException {
    Message msg = MsgPicker.getMsg();

    File cwd = new File("");
    logger.debug("Current path: {}", cwd.getAbsolutePath());
    logger.debug("DiagnosisInfoCLI args: {}", Arrays.toString(args));
    File script = new File(KylinConfig.getKylinHome() + File.separator + "bin", "diag.sh");
    if (!script.exists()) {
        throw new BadRequestException(
                String.format(Locale.ROOT, msg.getDIAG_NOT_FOUND(), script.getAbsolutePath()));
    }

    String diagCmd = script.getAbsolutePath() + " " + StringUtils.join(args, " ");
    CliCommandExecutor executor = KylinConfig.getInstanceFromEnv().getCliCommandExecutor();
    Pair<Integer, String> cmdOutput = executor.execute(diagCmd);

    if (cmdOutput.getFirst() != 0) {
        throw new BadRequestException(msg.getGENERATE_DIAG_PACKAGE_FAIL());
    }
}
 
Example #2
Source File: JobController.java    From kylin-on-parquet-v2 with 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 #3
Source File: ProjectService.java    From kylin with Apache License 2.0 6 votes vote down vote up
@PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN)
public ProjectInstance createProject(ProjectInstance newProject) throws IOException {
    Message msg = MsgPicker.getMsg();

    String projectName = newProject.getName();
    String description = newProject.getDescription();
    LinkedHashMap<String, String> overrideProps = newProject.getOverrideKylinProps();

    ProjectInstance currentProject = getProjectManager().getProject(projectName);

    if (currentProject != null) {
        throw new BadRequestException(String.format(Locale.ROOT, msg.getPROJECT_ALREADY_EXIST(), projectName));
    }
    String owner = SecurityContextHolder.getContext().getAuthentication().getName();
    ProjectInstance createdProject = getProjectManager().createProject(projectName, owner, description,
            overrideProps);
    accessService.init(createdProject, AclPermission.ADMINISTRATION);
    logger.debug("New project created.");

    return createdProject;
}
 
Example #4
Source File: CubeController.java    From kylin-on-parquet-v2 with 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 #5
Source File: ProjectController.java    From kylin-on-parquet-v2 with 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 #6
Source File: UserController.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private void completeAuthorities(ManagedUser managedUser) {
    List<SimpleGrantedAuthority> detailRoles = Lists.newArrayList(managedUser.getAuthorities());
    for (SimpleGrantedAuthority authority : detailRoles) {
        try {
            if (!userGroupService.exists(authority.getAuthority())) {
                throw new BadRequestException(String.format(Locale.ROOT,
                        "user's authority:%s is not found in user group", authority.getAuthority()));
            }
        } catch (IOException e) {
            logger.error("Get user group error: {}", e.getMessage());
        }
    }
    if (!detailRoles.contains(ALL_USERS_AUTH)) {
        detailRoles.add(ALL_USERS_AUTH);
    }
    managedUser.setGrantedAuthorities(detailRoles);
}
 
Example #7
Source File: JobController.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
/**
 * Cancel/discard a job
 * 
 * @return
 * @throws IOException
 */
@RequestMapping(value = "/{jobId}/cancel", method = { RequestMethod.PUT }, produces = { "application/json" })
@ResponseBody
public JobInstance cancel(@PathVariable String jobId) {

    try {
        final JobInstance jobInstance = jobService.getJobInstance(jobId);
        if (jobInstance == null) {
            throw new BadRequestException("Cannot find job: " + jobId);
        }
        jobService.cancelJob(jobInstance);
        return jobService.getJobInstance(jobId);
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
        throw new InternalErrorException(e);
    }
}
 
Example #8
Source File: JobController.java    From kylin-on-parquet-v2 with 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 #9
Source File: ModelService.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
public void primaryCheck(DataModelDesc modelDesc) {
    Message msg = MsgPicker.getMsg();

    if (modelDesc == null) {
        throw new BadRequestException(msg.getINVALID_MODEL_DEFINITION());
    }

    String modelName = modelDesc.getName();

    if (StringUtils.isEmpty(modelName)) {
        logger.info("Model name should not be empty.");
        throw new BadRequestException(msg.getEMPTY_MODEL_NAME());
    }
    if (!ValidateUtil.isAlphanumericUnderscore(modelName)) {
        logger.info("Invalid model name {}, only letters, numbers and underscore supported.", modelDesc.getName());
        throw new BadRequestException(String.format(Locale.ROOT, msg.getINVALID_MODEL_NAME(), modelName));
    }
}
 
Example #10
Source File: JobController.java    From kylin with 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 #11
Source File: JobController.java    From kylin with Apache License 2.0 6 votes vote down vote up
/**
 * Resume a cube job
 * 
 * @return
 * @throws IOException
 */
@RequestMapping(value = "/{jobId}/resume", method = { RequestMethod.PUT }, produces = { "application/json" })
@ResponseBody
public JobInstance resume(@PathVariable String jobId) {
    try {
        final JobInstance jobInstance = jobService.getJobInstance(jobId);
        if (jobInstance == null) {
            throw new BadRequestException("Cannot find job: " + jobId);
        }
        jobService.resumeJob(jobInstance);
        return jobService.getJobInstance(jobId);
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
        throw new InternalErrorException(e);
    }
}
 
Example #12
Source File: JobController.java    From kylin with Apache License 2.0 6 votes vote down vote up
/**
 * resubmit streaming segment
 *
 * @throws IOException
 */
@RequestMapping(value = "/{jobId}/resubmit", method = { RequestMethod.PUT }, produces = {
        "application/json" })
@ResponseBody
public void resubmitJob(@PathVariable String jobId) throws IOException {
    try {
        final JobInstance jobInstance = jobService.getJobInstance(jobId);
        if (jobInstance == null) {
            throw new BadRequestException("Cannot find job: " + jobId);
        }
        jobService.resubmitJob(jobInstance);
    } catch (Exception e) {
        logger.error(e.getLocalizedMessage(), e);
        throw e;
    }
}
 
Example #13
Source File: CubeService.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
public void checkEnableCubeCondition(CubeInstance cube) {
    aclEvaluate.checkProjectWritePermission(cube);
    Message msg = MsgPicker.getMsg();
    String cubeName = cube.getName();

    RealizationStatusEnum ostatus = cube.getStatus();

    if (!cube.getStatus().equals(RealizationStatusEnum.DISABLED)) {
        throw new BadRequestException(
                String.format(Locale.ROOT, msg.getENABLE_NOT_DISABLED_CUBE(), cubeName, ostatus));
    }

    if (cube.getSegments(SegmentStatusEnum.READY).size() == 0 && !cube.getDescriptor().isStreamingCube()) {
        throw new BadRequestException(String.format(Locale.ROOT, msg.getNO_READY_SEGMENT(), cubeName));
    }

    if (!cube.getDescriptor().checkSignature()) {
        throw new BadRequestException(
                String.format(Locale.ROOT, msg.getINCONSISTENT_CUBE_DESC_SIGNATURE(), cube.getDescriptor()));
    }
}
 
Example #14
Source File: CubeController.java    From kylin with 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 #15
Source File: CubeService.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN
        + " or hasPermission(#project, 'ADMINISTRATION') or hasPermission(#project, 'MANAGEMENT')")
public CubeDesc saveCube(CubeDesc desc, ProjectInstance project) throws IOException {
    Message msg = MsgPicker.getMsg();

    desc.setDraft(false);
    if (desc.getUuid() == null)
        desc.updateRandomUuid();

    try {
        createCubeAndDesc(project, desc);
    } catch (AccessDeniedException accessDeniedException) {
        throw new ForbiddenException(msg.getUPDATE_CUBE_NO_RIGHT());
    }

    if (desc.isBroken()) {
        throw new BadRequestException(desc.getErrorsAsString());
    }

    return desc;
}
 
Example #16
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 #17
Source File: AclService.java    From kylin-on-parquet-v2 with 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 #18
Source File: CubeService.java    From kylin with Apache License 2.0 6 votes vote down vote up
@PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN
        + " or hasPermission(#project, 'ADMINISTRATION') or hasPermission(#project, 'MANAGEMENT')")
public CubeDesc saveCube(CubeDesc desc, ProjectInstance project) throws IOException {
    Message msg = MsgPicker.getMsg();

    desc.setDraft(false);
    if (desc.getUuid() == null)
        desc.updateRandomUuid();

    try {
        createCubeAndDesc(project, desc);
    } catch (AccessDeniedException accessDeniedException) {
        throw new ForbiddenException(msg.getUPDATE_CUBE_NO_RIGHT());
    }

    if (desc.isBroken()) {
        throw new BadRequestException(desc.getErrorsAsString());
    }

    return desc;
}
 
Example #19
Source File: AccessService.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Transactional
@PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#ae, 'ADMINISTRATION')")
public void clean(AclEntity ae, boolean deleteChildren) {
    Message msg = MsgPicker.getMsg();

    if (ae == null) {
        throw new BadRequestException(msg.getACL_DOMAIN_NOT_FOUND());
    }

    // For those may have null uuid, like DataModel, won't delete Acl.
    if (ae.getId() == null)
        return;

    ObjectIdentity objectIdentity = new ObjectIdentityImpl(ae);

    try {
        aclService.deleteAcl(objectIdentity, deleteChildren);
    } catch (NotFoundException e) {
        //do nothing?
    }
}
 
Example #20
Source File: JobService.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private void checkAllowOptimization(CubeInstance cube, Set<Long> cuboidsRecommend) {
    Segments<CubeSegment> buildingSegments = cube.getBuildingSegments();
    if (buildingSegments.size() > 0) {
        throw new BadRequestException("The cube " + cube.getName() + " has building segments " + buildingSegments
                + ". It's not allowed for optimization");
    }
    long baseCuboid = cube.getCuboidScheduler().getBaseCuboidId();
    if (!cuboidsRecommend.contains(baseCuboid)) {
        throw new BadRequestException("The recommend cuboids should contain the base cuboid " + baseCuboid);
    }
    Set<Long> currentCuboidSet = cube.getCuboidScheduler().getAllCuboidIds();
    if (currentCuboidSet.equals(cuboidsRecommend)) {
        throw new BadRequestException(
                "The recommend cuboids are the same as the current cuboids. It's no need to do optimization.");
    }
}
 
Example #21
Source File: AccessService.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Transactional
@PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#ae, 'ADMINISTRATION')")
public void batchGrant(AclEntity ae, Map<Sid, Permission> sidToPerm) {
    Message msg = MsgPicker.getMsg();

    if (ae == null)
        throw new BadRequestException(msg.getACL_DOMAIN_NOT_FOUND());
    if (sidToPerm == null)
        throw new BadRequestException(msg.getACL_PERMISSION_REQUIRED());

    MutableAclRecord acl;
    try {
        acl = aclService.readAcl(new ObjectIdentityImpl(ae));
    } catch (NotFoundException e) {
        acl = init(ae, null);
    }

    for (Sid sid : sidToPerm.keySet()) {
        secureOwner(acl, sid);
    }
    aclService.batchUpsertAce(acl, sidToPerm);
}
 
Example #22
Source File: AclService.java    From kylin with 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 #23
Source File: DiagnosisService.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private String getDiagnosisPackageName(File destDir) {
    Message msg = MsgPicker.getMsg();

    File[] files = destDir.listFiles();
    if (files == null) {
        throw new BadRequestException(
                String.format(Locale.ROOT, msg.getDIAG_PACKAGE_NOT_AVAILABLE(), destDir.getAbsolutePath()));
    }
    for (File subDir : files) {
        if (subDir.isDirectory()) {
            for (File file : subDir.listFiles()) {
                if (file.getName().endsWith(".zip")) {
                    return file.getAbsolutePath();
                }
            }
        }
    }
    throw new BadRequestException(
            String.format(Locale.ROOT, msg.getDIAG_PACKAGE_NOT_FOUND(), destDir.getAbsolutePath()));
}
 
Example #24
Source File: DiagnosisService.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private void runDiagnosisCLI(String[] args) throws IOException {
    Message msg = MsgPicker.getMsg();

    File cwd = new File("");
    logger.debug("Current path: {}", cwd.getAbsolutePath());
    logger.debug("DiagnosisInfoCLI args: {}", Arrays.toString(args));
    File script = new File(KylinConfig.getKylinHome() + File.separator + "bin", "diag.sh");
    if (!script.exists()) {
        throw new BadRequestException(
                String.format(Locale.ROOT, msg.getDIAG_NOT_FOUND(), script.getAbsolutePath()));
    }

    String diagCmd = script.getAbsolutePath() + " " + StringUtils.join(args, " ");
    CliCommandExecutor executor = KylinConfig.getInstanceFromEnv().getCliCommandExecutor();
    Pair<Integer, String> cmdOutput = executor.execute(diagCmd);

    if (cmdOutput.getFirst() != 0) {
        throw new BadRequestException(msg.getGENERATE_DIAG_PACKAGE_FAIL());
    }
}
 
Example #25
Source File: EncodingService.java    From kylin with Apache License 2.0 6 votes vote down vote up
public List<String> getValidEncodings(DataType dataType) {
    Message msg = MsgPicker.getMsg();

    if (dataType.isIntegerFamily()) {
        return Lists.newArrayList(BooleanDimEnc.ENCODING_NAME, DateDimEnc.ENCODING_NAME, TimeDimEnc.ENCODING_NAME,
                DictionaryDimEnc.ENCODING_NAME, IntegerDimEnc.ENCODING_NAME);
    } else if (dataType.isNumberFamily()) { //numbers include integers
        return Lists.newArrayList(DictionaryDimEnc.ENCODING_NAME);
    } else if (dataType.isDateTimeFamily()) {
        return Lists.newArrayList(DateDimEnc.ENCODING_NAME, TimeDimEnc.ENCODING_NAME,
                DictionaryDimEnc.ENCODING_NAME);
    } else if (dataType.isStringFamily()) {
        return Lists.newArrayList(BooleanDimEnc.ENCODING_NAME, DictionaryDimEnc.ENCODING_NAME,
                FixedLenDimEnc.ENCODING_NAME, //
                FixedLenHexDimEnc.ENCODING_NAME, IntegerDimEnc.ENCODING_NAME);
    } else {
        throw new BadRequestException(String.format(Locale.ROOT, msg.getVALID_ENCODING_NOT_AVAILABLE(), dataType));
    }
}
 
Example #26
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 #27
Source File: AccessService.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Transactional
@PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#ae, 'ADMINISTRATION')")
public MutableAclRecord grant(AclEntity ae, Permission permission, Sid sid) {
    Message msg = MsgPicker.getMsg();

    if (ae == null)
        throw new BadRequestException(msg.getACL_DOMAIN_NOT_FOUND());
    if (permission == null)
        throw new BadRequestException(msg.getACL_PERMISSION_REQUIRED());
    if (sid == null)
        throw new BadRequestException(msg.getSID_REQUIRED());

    MutableAclRecord acl = null;
    try {
        acl = aclService.readAcl(new ObjectIdentityImpl(ae));
    } catch (NotFoundException e) {
        acl = init(ae, null);
    }

    secureOwner(acl, sid);

    return aclService.upsertAce(acl, sid, permission);
}
 
Example #28
Source File: CubeService.java    From kylin with Apache License 2.0 5 votes vote down vote up
public void validateCubeDesc(CubeDesc desc, boolean isDraft) {
    Message msg = MsgPicker.getMsg();

    if (desc == null) {
        throw new BadRequestException(msg.getINVALID_CUBE_DEFINITION());
    }

    String cubeName = desc.getName();
    if (StringUtils.isEmpty(cubeName)) {
        logger.info("Cube name should not be empty.");
        throw new BadRequestException(msg.getEMPTY_CUBE_NAME());
    }
    if (!ValidateUtil.isAlphanumericUnderscore(cubeName)) {
        logger.info("Invalid Cube name {}, only letters, numbers and underscore supported.", cubeName);
        throw new BadRequestException(String.format(Locale.ROOT, msg.getINVALID_CUBE_NAME(), cubeName));
    }

    if (!isDraft) {
        DataModelDesc modelDesc = modelService.getDataModelManager().getDataModelDesc(desc.getModelName());
        if (modelDesc == null) {
            throw new BadRequestException(
                    String.format(Locale.ROOT, msg.getMODEL_NOT_FOUND(), desc.getModelName()));
        }

        if (modelDesc.isDraft()) {
            logger.info("Cannot use draft model.");
            throw new BadRequestException(
                    String.format(Locale.ROOT, msg.getUSE_DRAFT_MODEL(), desc.getModelName()));
        }
    }
}
 
Example #29
Source File: ExternalFilterController.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "", method = { RequestMethod.GET }, produces = { "application/json" })
@ResponseBody
public List<ExternalFilterDesc> getExternalFilters(@RequestParam(value = "project", required = true) String project)
        throws IOException {
    if (!ValidateUtil.isAlphanumericUnderscore(project)) {
        throw new BadRequestException(String.format(Locale.ROOT, "Invalid Project name %s.", project));
    }
    List<ExternalFilterDesc> filterDescs = Lists.newArrayList();
    filterDescs.addAll(extFilterService.getProjectManager().listExternalFilterDescs(project).values());
    return filterDescs;
}
 
Example #30
Source File: JobService.java    From kylin with Apache License 2.0 5 votes vote down vote up
public JobInstance submitLookupSnapshotJob(CubeInstance cube, String lookupTable, List<String> segmentIDs,
        String submitter) throws IOException {
    Message msg = MsgPicker.getMsg();
    TableDesc tableDesc = getTableManager().getTableDesc(lookupTable, cube.getProject());
    if (tableDesc.isView()) {
        throw new BadRequestException(
                String.format(Locale.ROOT, msg.getREBUILD_SNAPSHOT_OF_VIEW(), tableDesc.getName()));
    }
    LookupSnapshotBuildJob job = new LookupSnapshotJobBuilder(cube, lookupTable, segmentIDs, submitter).build();
    getExecutableManager().addJob(job);

    JobInstance jobInstance = getLookupSnapshotBuildJobInstance(job);
    return jobInstance;
}