Java Code Examples for org.apache.kylin.cube.model.CubeDesc#getUuid()

The following examples show how to use org.apache.kylin.cube.model.CubeDesc#getUuid() . 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: 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 2
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 3
Source File: CacheControllerTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testClearCacheForCubeMigration() throws IOException {
    KylinConfig config = KylinConfig.getInstanceFromEnv();
    String CUBENAME = "test_kylin_cube_without_slr_desc";

    CubeDescManager cubeDescManager = CubeDescManager.getInstance(config);
    CubeDesc cubeDesc = cubeDescManager.getCubeDesc(CUBENAME);
    DataModelDesc modelDesc = cubeDesc.getModel();
    Map<String, String> tableToProjects = new HashMap<>();
    for (TableRef tableRef : modelDesc.getAllTables()) {
        tableToProjects.put(tableRef.getTableIdentity(), tableRef.getTableDesc().getProject());
    }

    String uuid = cubeDesc.getUuid();
    String signature = cubeDesc.getSignature();

    assertEquals(cubeDesc.getRetentionRange(), 0);

    //update cubeDesc
    cubeDesc.setRetentionRange(2018);
    cubeDesc.updateRandomUuid();

    //directly update metadata in store to simulate cube migration
    Serializer<CubeDesc> cubeDescSerializer = new JsonSerializer<CubeDesc>(CubeDesc.class);
    getStore().checkAndPutResource(cubeDesc.getResourcePath(), cubeDesc, cubeDescSerializer);

    CubeMigrationRequest request = new CubeMigrationRequest();
    request.setCube(cubeDesc.getName());
    request.setModel(modelDesc.getName());
    request.setProject(modelDesc.getProject());
    request.setTableToProjects(tableToProjects);

    cacheController.clearCacheForCubeMigration(request);

    assertEquals(2018, cubeDescManager.getCubeDesc(CUBENAME).getRetentionRange());
    assertEquals(signature, cubeDescManager.getCubeDesc(CUBENAME).getSignature());
    assertNotEquals(uuid, cubeDescManager.getCubeDesc(CUBENAME).getUuid());
}
 
Example 4
Source File: CubeDescManager.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new CubeDesc
 */
public CubeDesc createCubeDesc(CubeDesc cubeDesc) throws IOException {
    try (AutoLock lock = descMapLock.lockForWrite()) {
        if (cubeDesc.getUuid() == null || cubeDesc.getName() == null)
            throw new IllegalArgumentException();
        if (cubeDescMap.containsKey(cubeDesc.getName()))
            throw new IllegalArgumentException("CubeDesc '" + cubeDesc.getName() + "' already exists");
        if (cubeDesc.isDraft())
            throw new IllegalArgumentException(String.format(Locale.ROOT, CUBE_SHOULD_NOT_BE_DRAFT_MSG, cubeDesc.getName()));

        try {
            cubeDesc.init(config);
        } catch (Exception e) {
            logger.warn("Broken cube desc " + cubeDesc, e);
            cubeDesc.addError(e.toString());
        }
        
        postProcessCubeDesc(cubeDesc);
        // Check base validation
        if (cubeDesc.isBroken()) {
            return cubeDesc;
        }
        // Semantic validation
        CubeMetadataValidator validator = new CubeMetadataValidator(config);
        ValidateContext context = validator.validate(cubeDesc);
        if (!context.ifPass()) {
            return cubeDesc;
        }

        cubeDesc.setSignature(cubeDesc.calculateSignature());

        // save resource
        crud.save(cubeDesc);
        
        return cubeDesc;
    }
}
 
Example 5
Source File: CubeDescManager.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Update CubeDesc with the input. Broadcast the event into cluster
 */
public CubeDesc updateCubeDesc(CubeDesc desc) throws IOException {
    try (AutoLock lock = descMapLock.lockForWrite()) {
        // Validate CubeDesc
        if (desc.getUuid() == null || desc.getName() == null)
            throw new IllegalArgumentException();
        String name = desc.getName();
        if (!cubeDescMap.containsKey(name))
            throw new IllegalArgumentException("CubeDesc '" + name + "' does not exist.");
        if (desc.isDraft())
            throw new IllegalArgumentException(String.format(Locale.ROOT, CUBE_SHOULD_NOT_BE_DRAFT_MSG, desc.getName()));

        try {
            desc.init(config);
        } catch (Exception e) {
            logger.warn("Broken cube desc " + desc, e);
            desc.addError(e.toString());
            return desc;
        }

        postProcessCubeDesc(desc);
        // Semantic validation
        CubeMetadataValidator validator = new CubeMetadataValidator(config);
        ValidateContext context = validator.validate(desc);
        if (!context.ifPass()) {
            return desc;
        }

        desc.setSignature(desc.calculateSignature());

        // save resource
        crud.save(desc);

        return desc;
    }
}
 
Example 6
Source File: CacheControllerTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testClearCacheForCubeMigration() throws IOException {
    KylinConfig config = KylinConfig.getInstanceFromEnv();
    String CUBENAME = "test_kylin_cube_without_slr_desc";

    CubeDescManager cubeDescManager = CubeDescManager.getInstance(config);
    CubeDesc cubeDesc = cubeDescManager.getCubeDesc(CUBENAME);
    DataModelDesc modelDesc = cubeDesc.getModel();
    Map<String, String> tableToProjects = new HashMap<>();
    for (TableRef tableRef : modelDesc.getAllTables()) {
        tableToProjects.put(tableRef.getTableIdentity(), tableRef.getTableDesc().getProject());
    }

    String uuid = cubeDesc.getUuid();
    String signature = cubeDesc.getSignature();

    assertEquals(cubeDesc.getRetentionRange(), 0);

    //update cubeDesc
    cubeDesc.setRetentionRange(2018);
    cubeDesc.updateRandomUuid();

    //directly update metadata in store to simulate cube migration
    Serializer<CubeDesc> cubeDescSerializer = new JsonSerializer<CubeDesc>(CubeDesc.class);
    getStore().checkAndPutResource(cubeDesc.getResourcePath(), cubeDesc, cubeDescSerializer);

    CubeMigrationRequest request = new CubeMigrationRequest();
    request.setCube(cubeDesc.getName());
    request.setModel(modelDesc.getName());
    request.setProject(modelDesc.getProject());
    request.setTableToProjects(tableToProjects);

    cacheController.clearCacheForCubeMigration(request);

    assertEquals(2018, cubeDescManager.getCubeDesc(CUBENAME).getRetentionRange());
    assertEquals(signature, cubeDescManager.getCubeDesc(CUBENAME).getSignature());
    assertNotEquals(uuid, cubeDescManager.getCubeDesc(CUBENAME).getUuid());
}
 
Example 7
Source File: CubeDescManager.java    From kylin with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new CubeDesc
 */
public CubeDesc createCubeDesc(CubeDesc cubeDesc) throws IOException {
    try (AutoLock lock = descMapLock.lockForWrite()) {
        if (cubeDesc.getUuid() == null || cubeDesc.getName() == null)
            throw new IllegalArgumentException();
        if (cubeDescMap.containsKey(cubeDesc.getName()))
            throw new IllegalArgumentException("CubeDesc '" + cubeDesc.getName() + "' already exists");
        if (cubeDesc.isDraft())
            throw new IllegalArgumentException(String.format(Locale.ROOT, CUBE_SHOULD_NOT_BE_DRAFT_MSG, cubeDesc.getName()));

        try {
            cubeDesc.init(config);
        } catch (Exception e) {
            logger.warn("Broken cube desc " + cubeDesc, e);
            cubeDesc.addError(e.toString());
        }
        
        postProcessCubeDesc(cubeDesc);
        // Check base validation
        if (cubeDesc.isBroken()) {
            return cubeDesc;
        }
        // Semantic validation
        CubeMetadataValidator validator = new CubeMetadataValidator(config);
        ValidateContext context = validator.validate(cubeDesc);
        if (!context.ifPass()) {
            return cubeDesc;
        }

        cubeDesc.setSignature(cubeDesc.calculateSignature());

        // save resource
        crud.save(cubeDesc);
        
        return cubeDesc;
    }
}
 
Example 8
Source File: CubeDescManager.java    From kylin with Apache License 2.0 5 votes vote down vote up
/**
 * Update CubeDesc with the input. Broadcast the event into cluster
 */
public CubeDesc updateCubeDesc(CubeDesc desc) throws IOException {
    try (AutoLock lock = descMapLock.lockForWrite()) {
        // Validate CubeDesc
        if (desc.getUuid() == null || desc.getName() == null)
            throw new IllegalArgumentException();
        String name = desc.getName();
        if (!cubeDescMap.containsKey(name))
            throw new IllegalArgumentException("CubeDesc '" + name + "' does not exist.");
        if (desc.isDraft())
            throw new IllegalArgumentException(String.format(Locale.ROOT, CUBE_SHOULD_NOT_BE_DRAFT_MSG, desc.getName()));

        try {
            desc.init(config);
        } catch (Exception e) {
            logger.warn("Broken cube desc " + desc, e);
            desc.addError(e.toString());
            return desc;
        }

        postProcessCubeDesc(desc);
        // Semantic validation
        CubeMetadataValidator validator = new CubeMetadataValidator(config);
        ValidateContext context = validator.validate(desc);
        if (!context.ifPass()) {
            return desc;
        }

        desc.setSignature(desc.calculateSignature());

        // save resource
        crud.save(desc);

        return desc;
    }
}
 
Example 9
Source File: CubeDescManager.java    From Kylin with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new CubeDesc
 * 
 * @param cubeDesc
 * @return
 * @throws IOException
 */
public CubeDesc createCubeDesc(CubeDesc cubeDesc) throws IOException {
    if (cubeDesc.getUuid() == null || cubeDesc.getName() == null)
        throw new IllegalArgumentException();
    if (cubeDescMap.containsKey(cubeDesc.getName()))
        throw new IllegalArgumentException("CubeDesc '" + cubeDesc.getName() + "' already exists");

    try {
        cubeDesc.init(config, getMetadataManager().getAllTablesMap());
    } catch (IllegalStateException e) {
        cubeDesc.addError(e.getMessage(), true);
    }
    // Check base validation
    if (!cubeDesc.getError().isEmpty()) {
        return cubeDesc;
    }
    // Semantic validation
    CubeMetadataValidator validator = new CubeMetadataValidator();
    ValidateContext context = validator.validate(cubeDesc, true);
    if (!context.ifPass()) {
        return cubeDesc;
    }

    cubeDesc.setSignature(cubeDesc.calculateSignature());

    String path = cubeDesc.getResourcePath();
    getStore().putResource(path, cubeDesc, CUBE_DESC_SERIALIZER);
    cubeDescMap.put(cubeDesc.getName(), cubeDesc);

    return cubeDesc;
}