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

The following examples show how to use org.apache.kylin.cube.model.CubeDesc#addError() . 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: CubeMetadataValidator.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public ValidateContext validate(CubeDesc cube) {
    ValidateContext context = new ValidateContext();
    for (IValidatorRule<CubeDesc> rule : rules) {
        rule.validate(cube, context);
    }

    for (ValidateContext.Result result : context.getResults()) {
        cube.addError(result.getLevel() + " : " + result.getMessage());
    }
    return context;
}
 
Example 2
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 3
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 4
Source File: CubeMetadataValidator.java    From kylin with Apache License 2.0 5 votes vote down vote up
public ValidateContext validate(CubeDesc cube) {
    ValidateContext context = new ValidateContext();
    for (IValidatorRule<CubeDesc> rule : rules) {
        rule.validate(cube, context);
    }

    for (ValidateContext.Result result : context.getResults()) {
        cube.addError(result.getLevel() + " : " + result.getMessage());
    }
    return context;
}
 
Example 5
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 6
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 7
Source File: CubeMetadataValidator.java    From Kylin with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * Inject errors info into cubeDesc
 * 
 * @param cubeDesc
 * @param context
 */
public void injectResult(CubeDesc cubeDesc, ValidateContext context) {
    ValidateContext.Result[] results = context.getResults();
    for (int i = 0; i < results.length; i++) {
        ValidateContext.Result result = results[i];
        cubeDesc.addError(result.getLevel() + " : " + result.getMessage(), true);
    }

}
 
Example 8
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;
}