public String getRepositoryName(){ return this.repo.getRepositoryName(); }
public String getRepositoryName(){ return this.repo.getRepositoryName(); }
public String getRepositoryName(){ return this.repo.getRepositoryName(); }
public DB getDB() { Mongo mongoInstance = dataSource.getMongoInstance(); String dbName = metaService.getRepository().getRepositoryName(); return mongoInstance.getDB(dbName); }
@Override public void validateMetaClass(String className) { MetaClass meta = repo.getMetadataService().getMetaClass(className); if (meta == null) { throw new MetaClassNotExistsException(repo.getRepositoryName(), className); } validator.validate(meta); }
@Test public void testLoadRepositories() { IRepositoryService repoService = RepositoryServiceFactory.createRepositoryService(ds, "localCMSServer"); Repository repo = repoService.getRepository("raptor-paas"); Assert.assertEquals("raptor-paas", repo.getRepositoryName()); repo = repoService.getRepository("software-deployment"); Assert.assertEquals("software-deployment", repo.getRepositoryName()); }
private void updateMetadataIndexOnBranch(String metaclassName, MetadataContext context, Repository repo) { MetaClass meta = repo.getMetadataService().getMetaClass(metaclassName); List<MetaClass> metas = new ArrayList<MetaClass>(); metas.add(meta); metas.addAll(meta.getDescendants()); EntityContext entityContext = new EntityContext(); entityContext.setDbConfig(context.getDbConfig()); entityContext.setSourceIp(context.getSourceIp()); entityContext.setRegistration(getDalImplementation(context.getAdditionalParameter().get(HistoryServiceImpl.DAL_PARAMETER))); branchService.ensureIndex(repo.getRepositoryName(), metas, entityContext); }
@Test public void testCreateRepository() { Repository createRepo = new Repository(); createRepo.setRepositoryName("testNewRepo-cmsServer"); Repository repo = server.createRepository(CMSPriority.NON_CRITICAL, createRepo); Assert.assertNotNull(server.getRepository(CMSPriority.NON_CRITICAL, repo.getRepositoryName())); IBranch branch = server.getBranch(CMSPriority.NON_CRITICAL, repo.getRepositoryName(), IBranch.DEFAULT_BRANCH, entityContext); Assert.assertNotNull(branch); }
@Override public MetaClass getMetaClass(String className, int version, MetadataContext context) { MetaClass m = getMetaClass(className); if (m == null || version < 0 || version == m.getVersion()) { return m; } if (historyService != null) { m = historyService.getHistory(repo.getRepositoryName(), className, version, context); if (m != null) { m.setMetadataService(this); setUpMetaClass(m, graph); } return m; } return null; }
@Override public List<Repository> getRepositories(MetadataContext ctx) { MetadataContext context = ctx != null ? ctx : new MetadataContext(); if (!context.isRefreshRepsitory()) { return cache.values(); } ExpirableCache<Repository> newCache = new ExpirableCache<Repository>(maxCacheSize, cacheExpiredTime); BasicDBObject query = new BasicDBObject(); query.put(Repository.STATE_FIELD, Repository.StateEnum.normal.toString()); List<Repository> result = new ArrayList<Repository>(); DBCursor cursor = repoCollection.find(query); while (cursor.hasNext()) { DBObject object = cursor.next(); Repository r = repositoryConverter.fromBson(object, Repository.class); createServiceForRepository(r); result.add(r); newCache.putObject(r.getRepositoryName(), r); } cache = newCache; return result; }
@Test public void testRepositoryConvert() { String repositoryName = "name"; Repository repo = new Repository(); repo.setRepositoryName(repositoryName); Date now = new Date(); repo.setCreateTime(now); repo.setState(Repository.StateEnum.normal); ObjectConverter<Repository> c = new ObjectConverter<Repository>(); String json = c.toJson(repo); Repository repo1 = c.fromJson(json, Repository.class); Assert.assertEquals(repo1.getRepositoryName(), repo.getRepositoryName()); Assert.assertEquals(repo1.getCreateTime(), repo.getCreateTime()); // Assert.assertEquals(repo1.getDeletedTime(), repo.getDeletedTime()); // Assert.assertEquals(repo1.getDeletingTime(), repo.getDeletingTime()); }
@Test public void testGetAll() { List<Repository> repos = repositoryService.getRepositories(new MetadataContext()); String repoName1 = "testGetAll1"; String repoName2 = "testGetAll2"; repositoryService.createRepository(new Repository(repoName1)); repositoryService.createRepository(new Repository(repoName2)); List<Repository> newRepos = repositoryService.getRepositories(new MetadataContext()); Assert.assertEquals(repos.size() + 2, newRepos.size()); boolean found1 = false; boolean found2 = false; for (Repository r : newRepos) { if (r.getRepositoryName().equals(repoName1)) found1 = true; if (r.getRepositoryName().equals(repoName2)) found2 = true; } Assert.assertTrue(found1 && found2); }
private IBranch createBranch(Repository repoInst, String branchName) { Branch branch = new Branch(); branch.setMainBranch(true); branch.setId(branchName); branch.setRepositoryName(repoInst.getRepositoryName()); return branch; }
private PersistenceContext createPersistentContext(IMetadataService metaService) { String repoName = metaService.getRepository().getRepositoryName(); EntityContext entContext = new EntityContext(); entContext.setRequestId(requestId); entContext.setSourceIp(sourceIP); entContext.setRegistration(registration); entContext.setDbConfig(dbConfig); IBranch branch = branchService.getBranch(repoName, branchName, entContext); if (branch == null) { throw new CmsEntMgrException(CmsEntMgrException.EntMgrErrCodeEnum.BRANCH_NOT_FOUND, "Branch not found: " + branchName); } return PersistenceContextFactory.createEntityPersistenceConext(metaService, branch, consistentPolicy, registration, true, dbConfig, getAdditionalCriteria()); }
@Override public int getCollectionCount(String dbCollectionName) { CheckConditions.checkNotNull(dbCollectionName, "Collection name can't be null!"); Integer count = cacheManager.getCountFromCache(dbCollectionName); if (count == null) { DBCollection col = this.mongo.getDB(repo.getRepositoryName()).getCollection(dbCollectionName); // read from primary only col.setReadPreference(ReadPreference.primary()); col.setWriteConcern(WriteConcern.SAFE); count = (Integer) col.getStats().get("count"); if (count == null) { count = 0; } else { cacheManager.putCountToCache(dbCollectionName, count); } } return count; }
@Test public void testRepositoryCreation() { String repoName = "testRepoCreation"; try { repositoryService.getRepository(repoName); Assert.fail(); } catch (Exception e) { // expected } Repository r = repositoryService.createRepository(new Repository("r1")); Assert.assertEquals("r1", r.getRepositoryName()); Assert.assertNotNull(repositoryService.getRepository(r.getRepositoryName())); Assert.assertNotNull(repositoryService.getRepositories(new MetadataContext())); }
@Test(expected=RepositoryExistsException.class) public void testRepositoryCreationException() { String repoName = "testRepoCreation"; try { repositoryService.getRepository(repoName); Assert.fail(); } catch (Exception e) { // expected } Repository r = null; r = repositoryService.createRepository(new Repository("r2")); Assert.assertEquals("r2", r.getRepositoryName()); r = repositoryService.createRepository(new Repository("r2")); }
/** * clean up two collections: main and branches */ public void cleanUp(){ //FIXME: didn't drop collection properly, only dropped collection for main branch. But "load" method used other branch name. logger.debug(String.format("To clean up all runtime data in repository %s", repo.getRepositoryName())); //drop main & history repository PersistenceContext mainContext = new PersistenceContext(metaService, DBCollectionPolicy.SplitByMetadata, ConsistentPolicy.safePolicy(), DalTestCons.MAIN_BRANCH + "_base"); mainContext.setRegistration(TestUtils.getTestDalImplemantation(dataSource)); mainContext.setMongoDataSource(dataSource); PersistenceContext histContext = new PersistenceContext(metaService, DBCollectionPolicy.SplitByMetadata, ConsistentPolicy.safePolicy(), DalTestCons.MAIN_BRANCH_HISTORY + "_base"); histContext.setRegistration(TestUtils.getTestDalImplemantation(dataSource)); histContext.setMongoDataSource(dataSource); List<MetaClass> metadataList = repo.getMetadataService().getMetaClasses(new MetadataContext()); for (MetaClass metadata : metadataList) { DBCollection mainCollection = mainContext.getDBCollection(metadata); System.out.println("dropping runtime data in " + mainCollection.getName()); mainCollection.drop(); DBCollection histCollection = histContext.getDBCollection(metadata); System.out.println("dropping runtime data in " + histCollection.getName()); histCollection.drop(); } } }
private String createDefaultBranch(Repository repo, EntityContext context) { Repository repoInst = repo; MetaClass branchClass = BranchMetaClass.getMetaClass(repoInst); PersistenceContext pcontext = new PersistenceContext(metaService, DBCollectionPolicy.Merged, context.getConsistentPolicy(), CMSConsts.BRANCH_DB_COLL_NAME, context.getRegistration()); SearchProjection searchProject = new SearchProjection(); searchProject.addField(ProjectionField.STAR); ISearchQuery query = new SearchQuery(branchClass, null, searchProject, context.getRegistration().searchStrategy); SearchOption option = new SearchOption(); SearchResult result = searchService.search(query, option, pcontext); List<IEntity> bsonList = result.getResultSet(); if (bsonList.size() == 0) { Branch branch = new Branch(); branch.setRepositoryName(repo.getRepositoryName()); branch.setMainBranch(true); branch.setId(IBranch.DEFAULT_BRANCH); return branchService.createBranch(branch, context).getId(); } else { // simply assume first one is the main return bsonList.get(0).getId(); } }
@Test public void testRespositoryInitialization() { String repoName = "testRepoCreationInit"; try { repositoryService.getRepository(repoName); Assert.fail(); } catch (Exception e) { // expected } Repository r = repositoryService.createRepository(new Repository(repoName)); Assert.assertEquals(repoName, r.getRepositoryName()); Assert.assertNotNull(HistoryMetaClass.getMetaClass(r)); Assert.assertNotNull(BranchMetaClass.getMetaClass(r)); try { HistoryMetaClass.createHistoryMetaClass(r); BranchMetaClass.createBranchMetaClass(r); } catch (Exception e) { //1. create history/branch metadata class doesn't throw error when the metadata is already exsits Assert.fail(); } }