org.apache.kylin.rest.request.CubeRequest Java Examples

The following examples show how to use org.apache.kylin.rest.request.CubeRequest. 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: 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 #2
Source File: BeanTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    try {
        BeanValidator.validateAccssor(ColumnMeta.class, new String[0]);
        BeanValidator.validateAccssor(TableMeta.class, new String[0]);
        BeanValidator.validateAccssor(SelectedColumnMeta.class, new String[0]);
        BeanValidator.validateAccssor(AccessRequest.class, new String[0]);
        BeanValidator.validateAccssor(CubeRequest.class, new String[0]);
        BeanValidator.validateAccssor(JobListRequest.class, new String[0]);
        BeanValidator.validateAccssor(SQLRequest.class, new String[0]);
        BeanValidator.validateAccssor(AccessEntryResponse.class, new String[0]);
        BeanValidator.validateAccssor(SQLResponse.class, new String[0]);
    } catch (IntrospectionException e) {
    }

    new SQLResponse(null, null, 0, true, null);

    SelectedColumnMeta coulmnMeta = new SelectedColumnMeta(false, false, false, false, 0, false, 0, null, null,
            null, null, null, 0, 0, 0, null, false, false, false);
    Assert.assertTrue(!coulmnMeta.isAutoIncrement());
    Assert.assertTrue(!coulmnMeta.isCaseSensitive());
    Assert.assertTrue(!coulmnMeta.isSearchable());
    Assert.assertTrue(!coulmnMeta.isCurrency());
    Assert.assertTrue(coulmnMeta.getIsNullable() == 0);
    Assert.assertTrue(!coulmnMeta.isSigned());

    Assert.assertEquals(Constant.ACCESS_HAS_ROLE_ADMIN, "hasRole('ROLE_ADMIN')");
    Assert.assertEquals(Constant.ACCESS_POST_FILTER_READ,
            "hasRole('ROLE_ADMIN') " + " or hasPermission(filterObject, 'ADMINISTRATION')"
                    + " or hasPermission(filterObject, 'MANAGEMENT')"
                    + " or hasPermission(filterObject, 'OPERATION')" + " or hasPermission(filterObject, 'READ')");
    Assert.assertEquals(Constant.FakeCatalogName, "defaultCatalog");
    Assert.assertEquals(Constant.FakeSchemaName, "defaultSchema");
    Assert.assertEquals(Constant.IDENTITY_ROLE, "role");
    Assert.assertEquals(Constant.IDENTITY_USER, "user");
}
 
Example #3
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 #4
Source File: BeanTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    try {
        BeanValidator.validateAccssor(ColumnMeta.class, new String[0]);
        BeanValidator.validateAccssor(TableMeta.class, new String[0]);
        BeanValidator.validateAccssor(SelectedColumnMeta.class, new String[0]);
        BeanValidator.validateAccssor(AccessRequest.class, new String[0]);
        BeanValidator.validateAccssor(CubeRequest.class, new String[0]);
        BeanValidator.validateAccssor(JobListRequest.class, new String[0]);
        BeanValidator.validateAccssor(SQLRequest.class, new String[0]);
        BeanValidator.validateAccssor(AccessEntryResponse.class, new String[0]);
        BeanValidator.validateAccssor(SQLResponse.class, new String[0]);
    } catch (IntrospectionException e) {
    }

    new SQLResponse(null, null, 0, true, null);

    SelectedColumnMeta coulmnMeta = new SelectedColumnMeta(false, false, false, false, 0, false, 0, null, null,
            null, null, null, 0, 0, 0, null, false, false, false);
    Assert.assertTrue(!coulmnMeta.isAutoIncrement());
    Assert.assertTrue(!coulmnMeta.isCaseSensitive());
    Assert.assertTrue(!coulmnMeta.isSearchable());
    Assert.assertTrue(!coulmnMeta.isCurrency());
    Assert.assertTrue(coulmnMeta.getIsNullable() == 0);
    Assert.assertTrue(!coulmnMeta.isSigned());

    Assert.assertEquals(Constant.ACCESS_HAS_ROLE_ADMIN, "hasRole('ROLE_ADMIN')");
    Assert.assertEquals(Constant.ACCESS_POST_FILTER_READ,
            "hasRole('ROLE_ADMIN') " + " or hasPermission(filterObject, 'ADMINISTRATION')"
                    + " or hasPermission(filterObject, 'MANAGEMENT')"
                    + " or hasPermission(filterObject, 'OPERATION')" + " or hasPermission(filterObject, 'READ')");
    Assert.assertEquals(Constant.FakeCatalogName, "defaultCatalog");
    Assert.assertEquals(Constant.FakeSchemaName, "defaultSchema");
    Assert.assertEquals(Constant.IDENTITY_ROLE, "role");
    Assert.assertEquals(Constant.IDENTITY_USER, "user");
}
 
Example #5
Source File: BeanTest.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    try {
        BeanValidator.validateAccssor(ColumnMeta.class, new String[0]);
        BeanValidator.validateAccssor(TableMeta.class, new String[0]);
        BeanValidator.validateAccssor(SelectedColumnMeta.class, new String[0]);
        BeanValidator.validateAccssor(AccessRequest.class, new String[0]);
        BeanValidator.validateAccssor(CubeRequest.class, new String[0]);
        BeanValidator.validateAccssor(JobListRequest.class, new String[0]);
        BeanValidator.validateAccssor(SQLRequest.class, new String[0]);
        BeanValidator.validateAccssor(AccessEntryResponse.class, new String[0]);
        BeanValidator.validateAccssor(SQLResponse.class, new String[0]);
    } catch (IntrospectionException e) {
    }

    new SQLResponse(null, null, null, 0, true, null);

    SelectedColumnMeta coulmnMeta = new SelectedColumnMeta(false, false, false, false, 0, false, 0, null, null, null, null, null, 0, 0, 0, null, false, false, false);
    Assert.assertTrue(!coulmnMeta.isAutoIncrement());
    Assert.assertTrue(!coulmnMeta.isCaseSensitive());
    Assert.assertTrue(!coulmnMeta.isSearchable());
    Assert.assertTrue(!coulmnMeta.isCurrency());
    Assert.assertTrue(coulmnMeta.getIsNullable() == 0);
    Assert.assertTrue(!coulmnMeta.isSigned());

    Assert.assertEquals(Constant.ACCESS_HAS_ROLE_ADMIN, "hasRole('ROLE_ADMIN')");
    Assert.assertEquals(Constant.ACCESS_POST_FILTER_READ, "hasRole('ROLE_ADMIN') or hasPermission(filterObject, 'READ') or hasPermission(filterObject, 'MANAGEMENT') " + "or hasPermission(filterObject, 'OPERATION') or hasPermission(filterObject, 'ADMINISTRATION')");
    Assert.assertEquals(Constant.FakeCatalogName, "defaultCatalog");
    Assert.assertEquals(Constant.FakeSchemaName, "defaultSchema");
    Assert.assertEquals(Constant.IDENTITY_ROLE, "role");
    Assert.assertEquals(Constant.IDENTITY_USER, "user");
}
 
Example #6
Source File: CubeControllerTest.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testBasics() throws IOException {
    CubeDesc[] cubes = cubeDescController.getCube("test_kylin_cube_with_slr_ready");
    Assert.assertNotNull(cubes);
    Assert.assertNotNull(cubeController.getSql("test_kylin_cube_with_slr_ready", "20130331080000_20131212080000"));
    Assert.assertNotNull(cubeController.getCubes(null, null, null, 0, 5));

    CubeDesc cube = cubes[0];
    CubeDesc newCube = new CubeDesc();
    String newCubeName = cube.getName() + "_test_save";

    try {
        cubeController.deleteCube(newCubeName);
    } catch (Exception e) {
        // it may not exist, ignore the exception
    }

    newCube.setName(newCubeName);
    newCube.setModelName(cube.getModelName());
    newCube.setModel(cube.getModel());
    newCube.setDimensions(cube.getDimensions());
    newCube.setHbaseMapping(cube.getHbaseMapping());
    newCube.setMeasures(cube.getMeasures());
    newCube.setRowkey(cube.getRowkey());
    newCube.setAggregationGroups(cube.getAggregationGroups());

    newCube.getModel().setLastModified(0);

    ObjectMapper cubeDescMapper = new ObjectMapper();
    StringWriter cubeDescWriter = new StringWriter();
    cubeDescMapper.writeValue(cubeDescWriter, newCube);

    ObjectMapper modelDescMapper = new ObjectMapper();
    StringWriter modelDescWriter = new StringWriter();
    modelDescMapper.writeValue(modelDescWriter, newCube.getModel());

    CubeRequest cubeRequest = new CubeRequest();
    cubeRequest.setCubeDescData(cubeDescWriter.toString());
    cubeRequest.setCubeName(newCube.getName());
    cubeRequest = cubeController.saveCubeDesc(cubeRequest);

    List<String> notifyList = Lists.newArrayList();
    notifyList.add("[email protected]");
    cubeController.updateNotifyList(newCubeName, notifyList);

    List<CubeInstanceResponse> cubeInstances = cubeController.getCubes(newCubeName, cube.getModelName(), "default",
            1, 0);

    CubeInstance cubeInstance = cubeController.getCube(cubeInstances.get(0).getName());
    Assert.assertTrue(cubeInstance.getDescriptor().getNotifyList().contains("[email protected]"));
    Assert.assertTrue(cubeInstance.getCost() == 495);
    cubeController.deleteCube(newCubeName);
}
 
Example #7
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;

}
 
Example #8
Source File: CubeController.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
private void updateRequest(CubeRequest request, boolean success, String message) {
    request.setCubeDescData("");
    request.setSuccessful(success);
    request.setMessage(message);
}
 
Example #9
Source File: CubeControllerTest.java    From kylin with Apache License 2.0 4 votes vote down vote up
@Test
public void testBasics() throws IOException {
    CubeDesc[] cubes = cubeDescController.getCube("test_kylin_cube_with_slr_ready");
    Assert.assertNotNull(cubes);
    Assert.assertNotNull(cubeController.getSql("test_kylin_cube_with_slr_ready", "20130331080000_20131212080000"));
    Assert.assertNotNull(cubeController.getCubes(null, null, null, 0, 5));

    CubeDesc cube = cubes[0];
    CubeDesc newCube = new CubeDesc();
    String newCubeName = cube.getName() + "_test_save";

    try {
        cubeController.deleteCube(newCubeName);
    } catch (Exception e) {
        // it may not exist, ignore the exception
    }

    newCube.setName(newCubeName);
    newCube.setModelName(cube.getModelName());
    newCube.setModel(cube.getModel());
    newCube.setDimensions(cube.getDimensions());
    newCube.setHbaseMapping(cube.getHbaseMapping());
    newCube.setMeasures(cube.getMeasures());
    newCube.setRowkey(cube.getRowkey());
    newCube.setAggregationGroups(cube.getAggregationGroups());

    newCube.getModel().setLastModified(0);

    ObjectMapper cubeDescMapper = new ObjectMapper();
    StringWriter cubeDescWriter = new StringWriter();
    cubeDescMapper.writeValue(cubeDescWriter, newCube);

    ObjectMapper modelDescMapper = new ObjectMapper();
    StringWriter modelDescWriter = new StringWriter();
    modelDescMapper.writeValue(modelDescWriter, newCube.getModel());

    CubeRequest cubeRequest = new CubeRequest();
    cubeRequest.setCubeDescData(cubeDescWriter.toString());
    cubeRequest.setCubeName(newCube.getName());
    cubeRequest = cubeController.saveCubeDesc(cubeRequest);

    List<String> notifyList = Lists.newArrayList();
    notifyList.add("[email protected]");
    cubeController.updateNotifyList(newCubeName, notifyList);

    List<CubeInstanceResponse> cubeInstances = cubeController.getCubes(newCubeName, cube.getModelName(), "default",
            1, 0);

    CubeInstance cubeInstance = cubeController.getCube(cubeInstances.get(0).getName());
    Assert.assertTrue(cubeInstance.getDescriptor().getNotifyList().contains("[email protected]"));
    Assert.assertTrue(cubeInstance.getCost() == 495);
    cubeController.deleteCube(newCubeName);
}
 
Example #10
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 #11
Source File: CubeController.java    From kylin with Apache License 2.0 4 votes vote down vote up
private void updateRequest(CubeRequest request, boolean success, String message) {
    request.setCubeDescData("");
    request.setSuccessful(success);
    request.setMessage(message);
}
 
Example #12
Source File: CubeController.java    From Kylin with Apache License 2.0 4 votes vote down vote up
private void updateRequest(CubeRequest request, boolean success, String message) {
    request.setCubeDescData("");
    request.setSuccessful(success);
    request.setMessage(message);
}
 
Example #13
Source File: CubeControllerTest.java    From Kylin with Apache License 2.0 4 votes vote down vote up
@Test
public void testBasics() throws IOException {
    CubeDesc[] cubes = (CubeDesc[]) cubeDescController.getCube("test_kylin_cube_with_slr_ready");
    Assert.assertNotNull(cubes);
    Assert.assertNotNull(cubeController.getSql("test_kylin_cube_with_slr_ready", "20130331080000_20131212080000"));
    Assert.assertNotNull(cubeController.getCubes(null, null, 0, 5));

    CubeDesc cube = cubes[0];
    CubeDesc newCube = new CubeDesc();
    String newCubeName = cube.getName() + "_test_save";

    try {
        cubeController.deleteCube(newCubeName);
    } catch (Exception e) {
        // it may not exist, ignore the exception
    }

    newCube.setName(newCubeName);
    newCube.setModelName(cube.getModelName());
    newCube.setModel(cube.getModel());
    newCube.setDimensions(cube.getDimensions());
    newCube.setHBaseMapping(cube.getHBaseMapping());
    newCube.setMeasures(cube.getMeasures());
    newCube.setConfig(cube.getConfig());
    newCube.setRowkey(cube.getRowkey());

    String newModelName = newCubeName + "_model_desc";
    newCube.getModel().setName(newModelName);//generate a random model
    newCube.getModel().setLastModified(0);

    ObjectMapper cubeDescMapper = new ObjectMapper();
    StringWriter cubeDescWriter = new StringWriter();
    cubeDescMapper.writeValue(cubeDescWriter, newCube);

    ObjectMapper modelDescMapper = new ObjectMapper();
    StringWriter modelDescWriter = new StringWriter();
    modelDescMapper.writeValue(modelDescWriter, newCube.getModel());

    CubeRequest cubeRequest = new CubeRequest();
    cubeRequest.setCubeDescData(cubeDescWriter.toString());
    cubeRequest.setModelDescData(modelDescWriter.toString());
    cubeRequest = cubeController.saveCubeDesc(cubeRequest);


    DataModelDesc model = modelController.getModel(newModelName);
    Assert.assertNotNull(model);

    List<String> notifyList = Lists.newArrayList();
    notifyList.add("[email protected]");
    cubeController.updateNotifyList(newCubeName, notifyList);
    cubeController.updateCubeCost(newCubeName, 80);

    List<CubeInstance> cubeInstances = cubeController.getCubes(newCubeName, "default", 1, 0);

    CubeInstance cubeInstance = cubeInstances.get(0);
    Assert.assertTrue(cubeInstance.getDescriptor().getNotifyList().contains("[email protected]"));
    Assert.assertTrue(cubeInstance.getCost() == 80);
    cubeController.deleteCube(newCubeName);
}