Java Code Examples for org.apache.kylin.metadata.project.ProjectInstance

The following examples show how to use org.apache.kylin.metadata.project.ProjectInstance. 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
protected static void populateSSWithCSVData(KylinConfig kylinConfig, String project, SparkSession sparkSession) {

        ProjectInstance projectInstance = ProjectManager.getInstance(kylinConfig).getProject(project);
        Preconditions.checkArgument(projectInstance != null);
        for (String table : projectInstance.getTables()) {

            if ("DEFAULT.STREAMING_TABLE".equals(table)) {
                continue;
            }
            if (!new File(String.format(Locale.ROOT, CSV_TABLE_DIR, table)).exists()) {
                continue;
            }
            TableDesc tableDesc = TableMetadataManager.getInstance(kylinConfig).getTableDesc(table, project);
            ColumnDesc[] columns = tableDesc.getColumns();
            StructType schema = new StructType();
            for (ColumnDesc column : columns) {
                schema = schema.add(column.getName(), convertType(column.getType()), false);
            }
            Dataset<Row> ret = sparkSession.read().schema(schema).csv(String.format(Locale.ROOT, CSV_TABLE_DIR, table));
            ret.createOrReplaceTempView(tableDesc.getName());
        }

    }
 
Example 2
Source Project: kylin   Source File: TableMetadataManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * the project-specific table desc will be expand by computed columns from the projects' models
 * when the projects' model list changed, project-specific table should be reset and get expanded
 * again
 */
public void resetProjectSpecificTableDesc(String prj) throws IOException {
    // avoid cyclic locks
    ProjectInstance project = ProjectManager.getInstance(config).getProject(prj);
    
    try (AutoLock lock = srcTableMapLock.lockForWrite()) {
        for (String tableName : project.getTables()) {
            String tableIdentity = getTableIdentity(tableName);
            String key = mapKey(tableIdentity, prj);
            TableDesc originTableDesc = srcTableMap.get(key);
            if (originTableDesc == null) {
                continue;
            }

            if (originTableDesc.isBorrowedFromGlobal()) {
                srcTableMap.removeLocal(key);//delete it so that getProjectSpecificTableDesc will create again
            } else {
                srcTableCrud.reload(key);
            }
        }
    }
}
 
Example 3
Source Project: kylin   Source File: ProjectControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAddUpdateProject() throws IOException {
    int originalProjectCount = projectController.getProjects(null, null).size();

    //test add project
    ProjectInstance project = new ProjectInstance();
    project.setName("new_project");
    ProjectInstance ret = projectController.saveProject(getProjectRequest(project, null));

    Assert.assertEquals(ret.getOwner(), "ADMIN");
    Assert.assertEquals(ProjectManager.getInstance(getTestConfig()).listAllProjects().size(), originalProjectCount + 1);

    //test update project description only
    ProjectInstance newProject2 = new ProjectInstance();
    newProject2.setName("new_project");
    newProject2.setDescription("hello world");
    projectController.updateProject(getProjectRequest(newProject2, "new_project"));

    Assert.assertEquals(ProjectManager.getInstance(getTestConfig()).listAllProjects().size(), originalProjectCount + 1);
    Assert.assertNotEquals(ProjectManager.getInstance(getTestConfig()).getProject("new_project"), null);
    Assert.assertEquals(ProjectManager.getInstance(getTestConfig()).getProject("new_project").getDescription(), "hello world");
}
 
Example 4
Source Project: kylin   Source File: TableService.java    License: Apache License 2.0 6 votes vote down vote up
public void checkHiveTableCompatibility(String prj, TableDesc tableDesc) throws Exception {
    Preconditions.checkNotNull(tableDesc.getDatabase());
    Preconditions.checkNotNull(tableDesc.getName());

    String database = tableDesc.getDatabase().toUpperCase(Locale.ROOT);
    String tableName = tableDesc.getName().toUpperCase(Locale.ROOT);
    ProjectInstance projectInstance = getProjectManager().getProject(prj);
    ISourceMetadataExplorer explr = SourceManager.getSource(projectInstance).getSourceMetadataExplorer();

    TableDesc hiveTableDesc;
    try {
        Pair<TableDesc, TableExtDesc> pair = explr.loadTableMetadata(database, tableName, prj);
        hiveTableDesc = pair.getFirst();
    } catch (Exception e) {
        logger.error("Fail to get metadata for hive table {} due to ", tableDesc.getIdentity(), e);
        throw new RuntimeException("Fail to get metadata for hive table " + tableDesc.getIdentity());
    }

    TableSchemaUpdateChecker.CheckResult result = getSchemaUpdateChecker().allowMigrate(tableDesc, hiveTableDesc);
    result.raiseExceptionWhenInvalid();
}
 
Example 5
Source Project: kylin   Source File: KylinTestBase.java    License: Apache License 2.0 6 votes vote down vote up
protected static void setupAll() throws Exception {
    //setup env
    HBaseMetadataTestCase.staticCreateTestMetadata();
    config = KylinConfig.getInstanceFromEnv();

    //setup cube conn
    String project = ProjectInstance.DEFAULT_PROJECT_NAME;
    cubeConnection = QueryConnection.getConnection(project);

    //setup h2
    h2Connection = DriverManager.getConnection("jdbc:h2:mem:db" + (h2InstanceCount++) + ";CACHE_SIZE=32072", "sa",
            "");
    // Load H2 Tables (inner join)
    H2Database h2DB = new H2Database(h2Connection, config, project);
    h2DB.loadAllTables();
}
 
Example 6
Source Project: kylin   Source File: HybridManager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onEntityChange(Broadcaster broadcaster, String entity, Event event, String cacheKey)
        throws IOException {
    if ("hybrid".equals(entity)) {
        String hybridName = cacheKey;

        try (AutoLock l = lock.lockForWrite()) {
            if (event == Event.DROP)
                hybridMap.removeLocal(hybridName);
            else
                crud.reloadQuietly(hybridName);
        }

        for (ProjectInstance prj : ProjectManager.getInstance(config).findProjects(RealizationType.HYBRID,
                hybridName)) {
            broadcaster.notifyProjectSchemaUpdate(prj.getName());
        }
    } else if ("cube".equals(entity)) {
        String cubeName = cacheKey;
        try (AutoLock l = lock.lockForWrite()) {
            for (HybridInstance hybrid : getHybridInstancesByChild(RealizationType.CUBE, cubeName)) {
                crud.reloadQuietly(hybrid.getName());
            }
        }
    }
}
 
Example 7
Source Project: Kylin   Source File: AclEntityFactory.java    License: Apache License 2.0 6 votes vote down vote up
public static RootPersistentEntity createAclEntity(String entityType, String uuid) {
    if ("CubeInstance".equals(entityType)) {
        CubeInstance cubeInstance = new CubeInstance();
        cubeInstance.setUuid(uuid);

        return cubeInstance;
    }

    if ("JobInstance".equals(entityType)) {
        JobInstance jobInstance = new JobInstance();
        jobInstance.setUuid(uuid);

        return jobInstance;
    }

    if ("ProjectInstance".equals(entityType)) {
        ProjectInstance projectInstance = new ProjectInstance();
        projectInstance.setUuid(uuid);

        return projectInstance;
    }

    throw new RuntimeException("Unsupported entity type!");
}
 
Example 8
Source Project: kylin-on-parquet-v2   Source File: ProjectControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAddUpdateProject() throws IOException {
    int originalProjectCount = projectController.getProjects(null, null).size();

    //test add project
    ProjectInstance project = new ProjectInstance();
    project.setName("new_project");
    ProjectInstance ret = projectController.saveProject(getProjectRequest(project, null));

    Assert.assertEquals(ret.getOwner(), "ADMIN");
    Assert.assertEquals(ProjectManager.getInstance(getTestConfig()).listAllProjects().size(), originalProjectCount + 1);

    //test update project description only
    ProjectInstance newProject2 = new ProjectInstance();
    newProject2.setName("new_project");
    newProject2.setDescription("hello world");
    projectController.updateProject(getProjectRequest(newProject2, "new_project"));

    Assert.assertEquals(ProjectManager.getInstance(getTestConfig()).listAllProjects().size(), originalProjectCount + 1);
    Assert.assertNotEquals(ProjectManager.getInstance(getTestConfig()).getProject("new_project"), null);
    Assert.assertEquals(ProjectManager.getInstance(getTestConfig()).getProject("new_project").getDescription(), "hello world");
}
 
Example 9
Source Project: kylin-on-parquet-v2   Source File: TableService.java    License: Apache License 2.0 6 votes vote down vote up
public void calculateCardinalityIfNotPresent(String[] tables, String submitter, String prj) throws Exception {
    // calculate cardinality for Hive source
    ProjectInstance projectInstance = getProjectManager().getProject(prj);
    if (projectInstance == null || projectInstance.getSourceType() != ISourceAware.ID_HIVE) {
        return;
    }
    TableMetadataManager metaMgr = getTableManager();
    ExecutableManager exeMgt = ExecutableManager.getInstance(getConfig());
    for (String table : tables) {
        TableExtDesc tableExtDesc = metaMgr.getTableExt(table, prj);
        String jobID = tableExtDesc.getJodID();
        if (null == jobID || ExecutableState.RUNNING != exeMgt.getOutput(jobID).getState()) {
            calculateCardinality(table, submitter, prj);
        }
    }
}
 
Example 10
Source Project: kylin-on-parquet-v2   Source File: CubeService.java    License: Apache License 2.0 6 votes vote down vote up
public CubeDesc updateCube(CubeInstance cube, CubeDesc desc, ProjectInstance project) throws IOException {
    aclEvaluate.checkProjectWritePermission(cube);
    Message msg = MsgPicker.getMsg();
    String projectName = project.getName();

    desc.setDraft(false);

    try {
        if (cube.getSegments().size() != 0 && !cube.getDescriptor().consistentWith(desc)) {
            throw new BadRequestException(
                    String.format(Locale.ROOT, msg.getINCONSISTENT_CUBE_DESC(), desc.getName()));
        }

        desc = updateCubeAndDesc(cube, desc, projectName, true);
    } catch (AccessDeniedException accessDeniedException) {
        throw new ForbiddenException(msg.getUPDATE_CUBE_NO_RIGHT());
    }

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

    return desc;
}
 
Example 11
Source Project: kylin-on-parquet-v2   Source File: CubeDescManager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onEntityChange(Broadcaster broadcaster, String entity, Event event, String cacheKey)
        throws IOException {
    String cubeDescName = cacheKey;
    CubeDesc cubeDesc = getCubeDesc(cubeDescName);
    String modelName = cubeDesc == null ? null : cubeDesc.getModelName();

    if (event == Event.DROP)
        removeLocalCubeDesc(cubeDescName);
    else
        reloadCubeDescQuietly(cubeDescName);

    for (ProjectInstance prj : ProjectManager.getInstance(config).findProjectsByModel(modelName)) {
        broadcaster.notifyProjectSchemaUpdate(prj.getName());
    }
}
 
Example 12
Source Project: kylin-on-parquet-v2   Source File: CubeManagerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateAndDrop() throws Exception {

    KylinConfig config = getTestConfig();
    CubeManager cubeMgr = CubeManager.getInstance(config);
    ProjectManager prjMgr = ProjectManager.getInstance(config);
    ResourceStore store = getStore();

    // clean legacy in case last run failed
    store.deleteResource("/cube/a_whole_new_cube.json");

    CubeDescManager cubeDescMgr = getCubeDescManager();
    CubeDesc desc = cubeDescMgr.getCubeDesc("test_kylin_cube_with_slr_desc");
    CubeInstance createdCube = cubeMgr.createCube("a_whole_new_cube", ProjectInstance.DEFAULT_PROJECT_NAME, desc,
            null);
    assertTrue(createdCube.equals(cubeMgr.getCube("a_whole_new_cube")));

    assertTrue(prjMgr.listAllRealizations(ProjectInstance.DEFAULT_PROJECT_NAME).contains(createdCube));

    CubeInstance droppedCube = CubeManager.getInstance(getTestConfig()).dropCube("a_whole_new_cube", false);
    assertTrue(createdCube.equals(droppedCube));

    assertTrue(!prjMgr.listAllRealizations(ProjectInstance.DEFAULT_PROJECT_NAME).contains(droppedCube));

    assertNull(CubeManager.getInstance(getTestConfig()).getCube("a_whole_new_cube"));
}
 
Example 13
Source Project: kylin   Source File: TableMetadataManager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onEntityChange(Broadcaster broadcaster, String entity, Event event, String cacheKey)
        throws IOException {
    try (AutoLock lock = srcTableMapLock.lockForWrite()) {
        if (event == Event.DROP)
            srcTableMap.removeLocal(cacheKey);
        else
            srcTableCrud.reloadQuietly(cacheKey);
    }

    TableProject tableProject = TableDesc.parseResourcePath(cacheKey);
    String table = tableProject.getTable();
    String prj = tableProject.getProject();

    if (prj == null) {
        for (ProjectInstance p : ProjectManager.getInstance(config).findProjectsByTable(table)) {
            broadcaster.notifyProjectSchemaUpdate(p.getName());
        }
    } else {
        broadcaster.notifyProjectSchemaUpdate(prj);
    }
}
 
Example 14
Source Project: kylin   Source File: RealizationSetCalculator.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String calculateSignature(KylinConfig config, SQLResponse sqlResponse, ProjectInstance project) {
    Set<String> realizations = getRealizations(config, sqlResponse.getCube(), project);
    if (realizations == null) {
        return null;
    }
    Set<RealizationSignature> signatureSet = Sets.newTreeSet();
    for (String realization : realizations) {
        RealizationSignature realizationSignature = getRealizationSignature(config, realization);
        if (realizationSignature != null) {
            signatureSet.add(realizationSignature);
        }
    }
    if (signatureSet.isEmpty()) {
        return null;
    }
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] signature = md.digest(signatureSet.toString().getBytes("UTF-8"));
        return new String(Base64.encodeBase64(signature), "UTF-8");
    } catch (Exception e) {
        logger.warn("Failed to calculate signature due to " + e);
        return null;
    }
}
 
Example 15
Source Project: kylin   Source File: AccessControllerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAuthInProjectLevel() throws Exception {
    List<AccessEntryResponse> aes = null;
    swichToAdmin();
    List<ProjectInstance> projects = projectController.getProjects(10000, 0);
    assertTrue(projects.size() > 0);
    ProjectInstance project = projects.get(0);
    swichToAnalyst();
    projects = projectController.getProjects(10000, 0);
    assertEquals(0, projects.size());
    //grant auth in project level
    swichToAdmin();
    aes = accessController.grant(PROJECT_INSTANCE, project.getUuid(), getAccessRequest(ANALYST, READ, true));
    swichToAnalyst();
    projects = projectController.getProjects(10000, 0);
    assertEquals(1, projects.size());

    //revoke auth
    swichToAdmin();
    AccessRequest request = getAccessRequest(ANALYST, READ, true);
    request.setAccessEntryId((Integer) aes.get(0).getId());
    accessController.revoke(PROJECT_INSTANCE, project.getUuid(), request);
    swichToAnalyst();
    projects = projectController.getProjects(10000, 0);
    assertEquals(0, projects.size());
}
 
Example 16
Source Project: ranger   Source File: RangerKylinAuthorizerTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Help function: mock kylin projects, to match projectUuid and projectName
 */
private static void mockKylinProjects() {
	KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
	ProjectManager projectManager = mock(ProjectManager.class);

	@SuppressWarnings({ "rawtypes", "unchecked" })
	Map<Class, Object> managersCache = (Map<Class, Object>) ReflectionTestUtils.getField(kylinConfig,
			"managersCache");
	managersCache.put(ProjectManager.class, projectManager);

	Answer<ProjectInstance> answer = new Answer<ProjectInstance>() {
		@Override
		public ProjectInstance answer(InvocationOnMock invocation) throws Throwable {
			Object[] args = invocation.getArguments();
			if (args == null || args.length == 0) {
				return null;
			}
			String uuid = (String) args[0];
			return uuid2Projects.get(uuid);
		}
	};
	when(projectManager.getPrjByUuid(anyString())).thenAnswer(answer);
}
 
Example 17
Source Project: kylin   Source File: DeployCoprocessorCLI.java    License: Apache License 2.0 6 votes vote down vote up
private static List<String> filterByProjects(List<String> allTableNames, List<String> projectNames) {
    ProjectManager projectManager = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv());
    CubeManager cubeManager = CubeManager.getInstance(KylinConfig.getInstanceFromEnv());

    List<String> result = Lists.newArrayList();
    for (String p : projectNames) {
        p = p.trim();
        if (p.endsWith(",")) {
            p = p.substring(0, p.length() - 1);
        }

        ProjectInstance projectInstance = projectManager.getProject(p);
        List<RealizationEntry> cubeList = projectInstance.getRealizationEntries(RealizationType.CUBE);
        for (RealizationEntry cube : cubeList) {
            CubeInstance cubeInstance = cubeManager.getCube(cube.getRealization());
            for (CubeSegment segment : cubeInstance.getSegments()) {
                String tableName = segment.getStorageLocationIdentifier();
                if (allTableNames.contains(tableName)) {
                    result.add(tableName);
                }
            }
        }
    }
    return result;
}
 
Example 18
Source Project: kylin-on-parquet-v2   Source File: ProjectService.java    License: Apache License 2.0 6 votes vote down vote up
@Deprecated
public List<ProjectInstance> listAllProjects(final Integer limit, final Integer offset) {
    List<ProjectInstance> projects = getProjectManager().listAllProjects();

    int climit = (null == limit) ? Integer.MAX_VALUE : limit;
    int coffset = (null == offset) ? 0 : offset;

    if (projects.size() <= coffset) {
        return Collections.emptyList();
    }

    if ((projects.size() - coffset) < climit) {
        return projects.subList(coffset, projects.size());
    }

    return projects.subList(coffset, coffset + climit);
}
 
Example 19
Source Project: kylin-on-parquet-v2   Source File: CubeService.java    License: Apache License 2.0 6 votes vote down vote up
public List<CubeInstance> listAllCubes(String projectName) {
    ProjectManager projectManager = getProjectManager();
    ProjectInstance project = projectManager.getProject(projectName);
    if (project == null) {
        return Collections.emptyList();
    }
    ArrayList<CubeInstance> result = new ArrayList<CubeInstance>();
    for (RealizationEntry projectDataModel : project.getRealizationEntries()) {
        if (projectDataModel.getType() == RealizationType.CUBE) {
            CubeInstance cube = getCubeManager().getCube(projectDataModel.getRealization());
            if (cube != null)
                result.add(cube);
            else
                logger.error("Cube instance " + projectDataModel.getRealization() + " is failed to load");
        }
    }
    return result;
}
 
Example 20
Source Project: ranger   Source File: RangerKylinAuthorizerTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * kylin read all projects success
 */
@Test
@WithMockUser(username = KYLIN, roles = { ROLE_USER })
public void readProjectAllWithAdminPermission() {
	for (ProjectInstance project : uuid2Projects.values()) {
		boolean result = aclEvaluate.hasProjectReadPermission(project);
		Assert.assertTrue(result);
	}
}
 
Example 21
Source Project: Kylin   Source File: CubeMigrationCLI.java    License: Apache License 2.0 5 votes vote down vote up
private static void addCubeIntoProject(String cubeName, String projectName) throws IOException {
    String projectResPath = ProjectInstance.concatResourcePath(projectName);
    if (!dstStore.exists(projectResPath))
        throw new IllegalStateException("The target project " + projectName + "does not exist");

    operations.add(new Opt(OptType.ADD_INTO_PROJECT, new Object[] { cubeName, projectName }));
}
 
Example 22
Source Project: kylin   Source File: ProjectController.java    License: Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/readable", method = { RequestMethod.GET }, produces = { "application/json" })
@ResponseBody
public List<ProjectInstance> getReadableProjects(@RequestParam(value = "limit", required = false) Integer limit,
        @RequestParam(value = "offset", required = false) Integer offset) {

    List<ProjectInstance> readableProjects = new ArrayList<ProjectInstance>();

    //list all projects first
    List<ProjectInstance> projectInstances = projectService.listAllProjects(null, null);

    for (ProjectInstance projectInstance : projectInstances) {

        if (projectInstance == null) {
            continue;
        }
        boolean hasProjectPermission = aclEvaluate.hasProjectReadPermission(projectInstance);
        if (hasProjectPermission) {
            readableProjects.add(projectInstance);
        }

    }
    int projectLimit = (null == limit) ? Integer.MAX_VALUE : limit;
    int projectOffset = (null == offset) ? 0 : offset;

    if (readableProjects.size() <= projectOffset) {
        return Collections.emptyList();
    }

    if ((readableProjects.size() - projectOffset) < projectLimit) {
        return readableProjects.subList(projectOffset, readableProjects.size());
    }

    return readableProjects.subList(projectOffset, projectOffset + projectLimit);
}
 
Example 23
Source Project: ranger   Source File: RangerKylinAuthorizerTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * zhangqiang read kylin_project success
 */
@Test
@WithMockUser(username = ZHANGQIANG, roles = { ROLE_USER })
public void readProjectKylinWithOperationPermission() {
	ProjectInstance project = name2Projects.get(KYLIN_PROJECT);
	boolean result = aclEvaluate.hasProjectReadPermission(project);
	Assert.assertTrue(result);
}
 
Example 24
Source Project: ranger   Source File: RangerKylinAuthorizerTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * admin read all projects sueecss
 */
@Test
@WithMockUser(username = ADMIN, roles = { ROLE_ADMIN })
public void readProjectAllAsRoleAdmin() {
	for (ProjectInstance project : uuid2Projects.values()) {
		boolean result = aclEvaluate.hasProjectReadPermission(project);
		Assert.assertTrue(result);
	}
}
 
Example 25
Source Project: kylin-on-parquet-v2   Source File: AclUtil.java    License: Apache License 2.0 5 votes vote down vote up
@PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN +
        " or hasPermission(#project, 'ADMINISTRATION')" +
        " or hasPermission(#project, 'MANAGEMENT')" +
        " or hasPermission(#project, 'OPERATION')")
public boolean hasProjectOperationPermission(ProjectInstance project) {
    return true;
}
 
Example 26
Source Project: kylin-on-parquet-v2   Source File: StreamingV2Service.java    License: Apache License 2.0 5 votes vote down vote up
@PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN
        + " or hasPermission(#project, 'ADMINISTRATION')")
public StreamingSourceConfig createStreamingConfig(StreamingSourceConfig config, ProjectInstance project) throws IOException {
    if (getStreamingManagerV2().getConfig(config.getName()) != null) {
        throw new InternalErrorException("The streamingSourceConfig named " + config.getName() + " already exists");
    }
    StreamingSourceConfig streamingSourceConfig = getStreamingManagerV2().saveStreamingConfig(config);
    return streamingSourceConfig;
}
 
Example 27
Source Project: kylin-on-parquet-v2   Source File: CubeMetaIngesterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testHappyIngest() {
    String srcPath = Thread.currentThread().getContextClassLoader().getResource("cloned_cube_and_model.zip").getPath();
    CubeMetaIngester.main(new String[] { "-project", "default", "-srcPath", srcPath });

    ProjectInstance project = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv()).getProject("default");
    Assert.assertEquals(1, Collections.frequency(project.getTables(), "DEFAULT.TEST_KYLIN_FACT"));
    Assert.assertTrue(project.getModels().contains("cloned_model"));
    Assert.assertTrue(project.getRealizationEntries().contains(RealizationEntry.create(RealizationType.CUBE, "cloned_cube")));

    getTestConfig().clearManagers();
    CubeInstance instance = CubeManager.getInstance(KylinConfig.getInstanceFromEnv()).getCube("cloned_cube");
    Assert.assertTrue(instance != null);
}
 
Example 28
Source Project: kylin-on-parquet-v2   Source File: CubeMetaIngesterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testHappyIngest2() {
    String srcPath = Thread.currentThread().getContextClassLoader().getResource("benchmark_meta.zip").getPath();
    CubeMetaIngester.main(new String[] { "-project", "default", "-srcPath", srcPath, "-overwriteTables", "true" });

    ProjectInstance project = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv()).getProject("default");
    Assert.assertEquals(1, Collections.frequency(project.getTables(), "SSB.CUSTOMER"));
    Assert.assertTrue(project.getModels().contains("benchmark_model"));
    Assert.assertTrue(project.getRealizationEntries().contains(RealizationEntry.create(RealizationType.CUBE, "benchmark_cube")));

    getTestConfig().clearManagers();
    CubeInstance instance = CubeManager.getInstance(KylinConfig.getInstanceFromEnv()).getCube("benchmark_cube");
    Assert.assertTrue(instance != null);
}
 
Example 29
Source Project: kylin   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 30
Source Project: Kylin   Source File: CubeService.java    License: Apache License 2.0 5 votes vote down vote up
@PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'MANAGEMENT')")
public CubeDesc updateCubeAndDesc(CubeInstance cube, CubeDesc desc, String newProjectName) throws UnknownHostException, IOException, JobException {
    final List<CubingJob> cubingJobs = listAllCubingJobs(cube.getName(), null, EnumSet.of(ExecutableState.READY, ExecutableState.RUNNING));
    if (!cubingJobs.isEmpty()) {
        throw new JobException("Cube schema shouldn't be changed with running job.");
    }

    try {
        if (!cube.getDescriptor().calculateSignature().equals(cube.getDescriptor().getSignature())) {
            this.releaseAllSegments(cube);
        }

        CubeDesc updatedCubeDesc = getCubeDescManager().updateCubeDesc(desc);

        int cuboidCount = CuboidCLI.simulateCuboidGeneration(updatedCubeDesc);
        logger.info("Updated cube " + cube.getName() + " has " + cuboidCount + " cuboids");

        ProjectManager projectManager = getProjectManager();
        if (!isCubeInProject(newProjectName, cube)) {
            String owner = SecurityContextHolder.getContext().getAuthentication().getName();
            ProjectInstance newProject = projectManager.moveRealizationToProject(RealizationType.CUBE, cube.getName(), newProjectName, owner);
            accessService.inherit(cube, newProject);
        }

        return updatedCubeDesc;
    } catch (IOException e) {
        throw new InternalErrorException("Failed to deal with the request.", e);
    }
}