private String getSourcePackVersion(CmsCI plat) { return plat.getAttribute("source").getDjValue() + ":" + plat.getAttribute("pack").getDjValue() + ":" + plat.getAttribute("version").getDjValue(); }
private boolean restoreMonitor(Long manifestId, Long ciId, CmsCI monitor, boolean writeMode) { if (!"true".equals(monitor.getAttributes().get(IS_ENABLED).getDjValue())) { return false; } boolean isHeartBeat = "true".equals(monitor.getAttributes().get(HEARTBEAT).getDjValue()); String hbDuration = monitor.getAttributes().get(DURATION).getDjValue(); String source = monitor.getCiName(); long checksum = getChecksum(monitor); String thresholdsJson = monitor.getAttributes().get(THRESHOLDS).getDjValue(); Threshold threshold = tsDao.getThreshold(manifestId, source); if (threshold == null) { logger.info( "RestoreMonitor###: threshold for manifestId:" + manifestId + " and source:" + source + " not found. Will add"); if (thresholdsJson == null || thresholdsJson.length() <= THRESHOLDS_JSON_SIZE_FLOOR) { thresholdsJson = "n"; } if (writeMode) { tsDao.addCiThresholds( ciId, manifestId, source, checksum, thresholdsJson, isHeartBeat, hbDuration); } return true; } return false; }
private void check4OpenRelease(CmsCI env, String nsPath) { if (hasOpenManifestRelease(nsPath)) { String message = "This environment has an open release. It needs to be discarded or committed before the design pull: " + env.getNsPath() + "/" + env.getCiName(); logger.info(message); throw new TransistorException(CmsError.TRANSISTOR_OPEN_MANIFEST_RELEASE, message); } }
private void processCloudDeletions(long envId, Set<Long> cloudsToRemove) { // looks like we need to delete some clouds // first lets see if we have any open releases CmsCI env = getEnv(envId); String manifestNsPath = env.getNsPath() + "/" + env.getCiName() + "/manifest"; String bomNsPath = env.getNsPath() + "/" + env.getCiName() + "/bom"; List<CmsRelease> manifestOpenReleases = rfcProcessor.getReleaseBy3(manifestNsPath, null, RELEASE_STATE_OPEN); if (manifestOpenReleases.size() > 0) { // throw exception on open release throw new TransistorException( CmsError.TRANSISTOR_OPEN_MANIFEST_RELEASE, "There is open release in this environment, you have to commit or discard before deleteing the clouds!"); } List<CmsRelease> bomOpenReleases = rfcProcessor.getReleaseBy3(bomNsPath, null, RELEASE_STATE_OPEN); if (bomOpenReleases.size() > 0) { // throw exception on open release throw new TransistorException( CmsError.TRANSISTOR_OPEN_BOM_RELEASE, "There is open BOM release in this environment, you have to deploy or discard before deleteing the clouds!"); } // if we still here lets check if there are any boms deployed to the clouds that user tries to // remove for (long cloidId : cloudsToRemove) { long deployedToRelsCount = cmProcessor.getCountToCIRelationsByNS( cloidId, BASE_DEPLOYED_TO, null, null, bomNsPath, true); if (deployedToRelsCount > 0) { // throw exception that there are active boms throw new TransistorException( CmsError.TRANSISTOR_BOM_INSTANCES_EXIST, "There are deployed instances in the cloud, please put the cloud in offline mode for every platform and deploy!"); } } // if everything cool, let remove Consumes relations from platforms and env for (long cloidId : cloudsToRemove) { List<CmsCIRelation> platformRels = cmProcessor.getFromCIRelationsNaked(envId, MANIFEST_COMPOSED_OF, MANIFEST_PLATFORM); for (CmsCIRelation platRel : platformRels) { List<CmsCIRelation> platformCloudRels = cmProcessor.getFromToCIRelations(platRel.getToCiId(), BASE_CONSUMES, cloidId); for (CmsCIRelation platCloudRel : platformCloudRels) { cmProcessor.deleteRelation(platCloudRel.getCiRelationId()); } } // now lets remove env consumes rel List<CmsCIRelation> envCloudRels = cmProcessor.getFromToCIRelations(envId, BASE_CONSUMES, cloidId); for (CmsCIRelation cloudRel : envCloudRels) { cmProcessor.deleteRelation(cloudRel.getCiRelationId()); } } }
@Override public long updateEnvClouds(long envId, List<CmsCIRelation> cloudRels, String userId) { // for now we will handle just new clouds List<CmsCIRelation> existingCloudRels = cmProcessor.getFromCIRelationsNaked(envId, BASE_CONSUMES, ACCOUNT_CLOUD); Set<Long> existingCloudIds = new HashSet<Long>(); for (CmsCIRelation rel : existingCloudRels) { existingCloudIds.add(rel.getToCiId()); } boolean needUpdate = false; for (CmsCIRelation requestRel : cloudRels) { if (!existingCloudIds.contains(requestRel.getToCiId())) { // this is new cloud lets add env->cloud rel cmProcessor.createRelation(requestRel); needUpdate = true; } else { cmProcessor.updateRelation(requestRel); existingCloudIds.remove(requestRel.getToCiId()); } } if (!existingCloudIds.isEmpty()) { // looks like we need to delete some clouds // first lets see if we have any open releases processCloudDeletions(envId, existingCloudIds); } if (needUpdate) { CmsCI env = getEnv(envId); String nsPath = env.getNsPath() + "/" + env.getCiName() + "/manifest"; List<CmsRfcRelation> compOfRels = cmRfcMrgProcessor.getFromCIRelations( envId, MANIFEST_COMPOSED_OF, MANIFEST_PLATFORM, "dj"); for (CmsRfcRelation compOfRel : compOfRels) { CmsRfcCI platform = compOfRel.getToRfcCi(); String platNs = platform.getNsPath(); manifestRfcProcessor.processClouds(env, platform, platNs, nsPath, userId, null, null, null); Set<String> missingSrvs = cloudUtil.getMissingServices(platform.getCiId()); if (missingSrvs.size() > 0) { logger.info( ">>>>> Not all services available for platform: " + platform.getCiName() + ", the missing services: " + missingSrvs.toString()); manifestRfcProcessor.disablePlatform(platform.getCiId(), userId); } logger.info("Done working on platform " + platform.getCiName()); } return populateParentRelease(env, nsPath); } else { return 0; } }
private long getChecksum(CmsCI monitor) { long checksum = 0; String thresholds = monitor.getAttributes().get("thresholds").getDfValue(); if (thresholds != null) { CRC32 crc = new CRC32(); String crcStr = thresholds + monitor.getAttributes().get(HEARTBEAT).getDfValue() + monitor.getAttributes().get(DURATION).getDfValue(); crc.update(crcStr.getBytes()); checksum = crc.getValue(); } return checksum; }
private long populateParentRelease(CmsCI env, String nsPath) { long releaseId = 0; // if we got new release lets populate parent releaseid with latest design CmsRelease manifestRelease = null; List<CmsRelease> manifestReleases = rfcProcessor.getLatestRelease(nsPath, "open"); if (manifestReleases.size() > 0) { manifestRelease = manifestReleases.get(0); } else { List<CmsRelease> closedManifestReleases = rfcProcessor.getLatestRelease(nsPath, "closed"); if (closedManifestReleases.size() > 0) { manifestRelease = closedManifestReleases.get(0); } } if (manifestRelease != null) { releaseId = manifestRelease.getReleaseId(); List<CmsRelease> designReleases = rfcProcessor.getLatestRelease(env.getNsPath(), "closed"); if (designReleases.size() > 0) { CmsRelease designRelease = designReleases.get(0); manifestRelease.setParentReleaseId(designRelease.getReleaseId()); rfcProcessor.updateRelease(manifestRelease); } } return releaseId; }
@Test(priority = 98) /** test local var where regex matches in middle not start */ public void processLocalVarDuo() { Map<String, String> localVars = new HashMap<String, String>(3); localVars.put("mylocal", "123456"); CmsCI ci = new CmsCI(); ci.setCiId(98); ci.setCiName("processLocalVarDuo"); Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(2); int i = 0; CmsCIAttribute attrL = new CmsCIAttribute(); attrL.setDjValue("/preamble/$OO_LOCAL{mylocal}/middle/$OO_LOCAL{mylocal}"); String nameOfAttribute = "my-only-attr"; attributes.put(nameOfAttribute, attrL); ci.setAttributes(attributes); Map<String, CmsCIAttribute> attributesBefore = ci.getAttributes(); for (Entry<String, CmsCIAttribute> e : attributesBefore.entrySet()) { System.out.println("*- b4 |" + e.getKey() + "->" + e.getValue().getDjValue()); } CmsUtil util = new CmsUtil(); dumpMaps(null, null, localVars); dumpCmsCIAttributes(ci); util.processAllVars(ci, null, null, localVars); dumpCmsCIAttributes(ci); for (Entry<String, CmsCIAttribute> a : ci.getAttributes().entrySet()) { String djKey = a.getKey(); String djAfter = a.getValue().getDjValue(); System.out.println("*after k>" + djKey + " v->" + djAfter); if (djKey.equals(nameOfAttribute)) { assertEquals(djAfter, "/preamble/123456/middle/123456"); } } }
@Test(priority = 150) /** * test variable that user did not set, instead it is empty string "" this is NOT a bad reference */ public void processLocalVarBlankValue() { Map<String, String> cloudVars = new HashMap<String, String>(3); cloudVars.put("FOO", ""); CmsCI ci = new CmsCI(); ci.setCiId(150); ci.setCiName("processLocalVarBlankValue"); Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(1); CmsCIAttribute attrL = new CmsCIAttribute(); attrL.setDjValue("$OO_CLOUD{FOO}"); String nameOfAttribute = "testingABlank"; attributes.put(nameOfAttribute, attrL); ci.setAttributes(attributes); Map<String, CmsCIAttribute> attributesBefore = ci.getAttributes(); for (Entry<String, CmsCIAttribute> e : attributesBefore.entrySet()) { System.out.println("*- b4 |" + e.getKey() + "->" + e.getValue().getDjValue()); } CmsUtil util = new CmsUtil(); dumpMaps(null, null, null); dumpCmsCIAttributes(ci); util.processAllVars(ci, cloudVars, null, null); dumpCmsCIAttributes(ci); for (Entry<String, CmsCIAttribute> a : ci.getAttributes().entrySet()) { String djKey = a.getKey(); String djAfter = a.getValue().getDjValue(); System.out.println("*after k>" + djKey + " v->" + djAfter); if (djKey.equals(nameOfAttribute)) { assertEquals(djAfter, "", "this is not a empty string as expected"); } } }
@Test(priority = 122) /** test variable that is not one of our OO_CLOUD/LOCAL/GLOBAL varieties */ public void processLocalVarNegativeSpelling() { Map<String, String> localVars = new HashMap<String, String>(1); localVars.put("groupId", "barrrrrr"); CmsCI ci = new CmsCI(); ci.setCiId(122); ci.setCiName("processLocalVarNegativeSpelling"); Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(1); CmsCIAttribute attrL = new CmsCIAttribute(); attrL.setDjValue("$OO_NOOCAL{groupId}"); // typo in place of $OO_LOCAL String nameOfAttribute = "irrelevantname"; attributes.put(nameOfAttribute, attrL); ci.setAttributes(attributes); Map<String, CmsCIAttribute> attributesBefore = ci.getAttributes(); for (Entry<String, CmsCIAttribute> e : attributesBefore.entrySet()) { System.out.println("*- b4 |" + e.getKey() + "->" + e.getValue().getDjValue()); } CmsUtil util = new CmsUtil(); dumpMaps(null, null, localVars); dumpCmsCIAttributes(ci); util.processAllVars(ci, null, null, localVars); dumpCmsCIAttributes(ci); for (Entry<String, CmsCIAttribute> a : ci.getAttributes().entrySet()) { String djKey = a.getKey(); String djAfter = a.getValue().getDjValue(); System.out.println("*after k>" + djKey + " v->" + djAfter); if (djKey.equals(nameOfAttribute)) { assertEquals(djAfter, "$OO_NOOCAL{groupId}"); // outcome is it stays as it } } }
@Test(priority = 134, expectedExceptions = CIValidationException.class) /** test variable that user did not set, it is exception bad reference */ public void processLocalVarNegativeMissingCloud() { CmsCI ci = new CmsCI(); ci.setCiId(134); ci.setCiName("processLocalVarNegativeMissingCloud"); Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(1); CmsCIAttribute attrL = new CmsCIAttribute(); attrL.setDjValue("$OO_CLOUD{not-cloudy}"); String nameOfAttribute = "sun"; attributes.put(nameOfAttribute, attrL); ci.setAttributes(attributes); Map<String, CmsCIAttribute> attributesBefore = ci.getAttributes(); for (Entry<String, CmsCIAttribute> e : attributesBefore.entrySet()) { System.out.println("*- b4 |" + e.getKey() + "->" + e.getValue().getDjValue()); } CmsUtil util = new CmsUtil(); dumpMaps(null, null, null); dumpCmsCIAttributes(ci); util.processAllVars(ci, null, null, null); dumpCmsCIAttributes(ci); }
private long checkPlatformPackCompliance( List<CmsCIRelation> designPlatRels, CmsCI env, String nsPath, String userId) { List<CmsCIRelation> manifestPlatRels = cmProcessor.getFromCIRelations( env.getCiId(), MANIFEST_COMPOSED_OF, null, MANIFEST_PLATFORM); Map<String, String> manifestPlatPacks = new HashMap<String, String>(manifestPlatRels.size()); for (CmsCIRelation manifestRel : manifestPlatRels) { CmsCI plat = manifestRel.getToCi(); String key = getPlatNameAndVersion(plat); String value = getSourcePackVersion(plat); manifestPlatPacks.put(key, value); } long newReleaseId = 0; for (CmsCIRelation designRel : designPlatRels) { CmsCI dPlat = designRel.getToCi(); String key = getPlatNameAndVersion(dPlat); String value = getSourcePackVersion(dPlat); if (manifestPlatPacks.containsKey(key) && !value.equals(manifestPlatPacks.get(key))) { String platNsPath = nsPath + "/" + dPlat.getCiName() + "/" + dPlat.getAttribute("major_version").getDfValue(); List<CmsRfcCI> mPlats = cmRfcMrgProcessor.getDfDjCi(platNsPath, MANIFEST_PLATFORM, dPlat.getCiName(), "dj"); if (mPlats.size() > 0) { newReleaseId = manifestRfcProcessor.deleteManifestPlatform(mPlats.get(0), userId); } } } return newReleaseId; }
@Test(priority = 130, expectedExceptions = CIValidationException.class) /** test variable that user did not set, it is exception bad reference */ public void processLocalVarNegativeMissingLocal() { Map<String, String> localVars = new HashMap<String, String>(1); localVars.put("aaaaaa", "ignore-me"); CmsCI ci = new CmsCI(); ci.setCiId(130); ci.setCiName("processLocalVarNegativeMissingLocal"); Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(1); CmsCIAttribute attrL = new CmsCIAttribute(); attrL.setDjValue("$OO_LOCAL{this-is-not-resolved}"); String nameOfAttribute = "trouble"; attributes.put(nameOfAttribute, attrL); ci.setAttributes(attributes); Map<String, CmsCIAttribute> attributesBefore = ci.getAttributes(); for (Entry<String, CmsCIAttribute> e : attributesBefore.entrySet()) { System.out.println("*- b4 |" + e.getKey() + "->" + e.getValue().getDjValue()); } CmsUtil util = new CmsUtil(); dumpMaps(null, null, localVars); dumpCmsCIAttributes(ci); util.processAllVars(ci, null, null, localVars); dumpCmsCIAttributes(ci); }
public DesignCIManifestRfcTouple call() { String oldThreadName = Thread.currentThread().getName(); try { Thread.currentThread().setName(getProcessingThreadName(oldThreadName, env.getCiId())); ManifestRfcContainer manifestPlatformRfcs = manifestRfcProcessor.processPlatform( platRelation.getToCi(), env, nsPath, userId, availMode); DesignCIManifestRfcTouple touple = new DesignCIManifestRfcTouple(platRelation.getToCi().getCiId(), manifestPlatformRfcs); return touple; } finally { countDownLatch.countDown(); Thread.currentThread().setName(oldThreadName); } }
@Test(priority = 132, expectedExceptions = CIValidationException.class) /** test variable that user did not set, it is exception bad reference */ public void processLocalVarNegativeMissingGlobal2() { Map<String, String> globalVars = new HashMap<String, String>(1); globalVars.put("cc", "ignore-distraction"); CmsCI ci = new CmsCI(); ci.setCiId(132); ci.setCiName("processLocalVarNegativeMissingGlobal2"); Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(1); CmsCIAttribute attrL = new CmsCIAttribute(); attrL.setDjValue("$OO_GLOBAL{where?}"); String nameOfAttribute = "nowh---ere"; attributes.put(nameOfAttribute, attrL); ci.setAttributes(attributes); Map<String, CmsCIAttribute> attributesBefore = ci.getAttributes(); for (Entry<String, CmsCIAttribute> e : attributesBefore.entrySet()) { System.out.println("*- b4 |" + e.getKey() + "->" + e.getValue().getDjValue()); } CmsUtil util = new CmsUtil(); dumpMaps(null, globalVars, null); dumpCmsCIAttributes(ci); util.processAllVars(ci, null, globalVars, null); dumpCmsCIAttributes(ci); }
@Test(priority = 90) /** * test local var where both Cloud and Global have that variable name and the one we want is from * the Cloud */ public void processLocalVarChoiceGlobalVsCloud() { // Variables for cloud, global, and locals Map<String, String> cloudVars = new HashMap<String, String>(3); cloudVars.put("common", "duolc"); Map<String, String> globalVars = new HashMap<String, String>(3); globalVars.put("common", "labolg"); Map<String, String> localVars = new HashMap<String, String>(3); localVars.put("common", "lacol"); CmsCI ci = new CmsCI(); ci.setCiId(90); ci.setCiName("processLocalVarChoiceGlobalVsCloud"); Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(2); int i = 0; CmsCIAttribute attrL = new CmsCIAttribute(); attrL.setDjValue("$OO_CLOUD{common}"); String nameOfAttribute = "my-one-attr"; attributes.put(nameOfAttribute, attrL); ci.setAttributes(attributes); Map<String, CmsCIAttribute> attributesBefore = ci.getAttributes(); for (Entry<String, CmsCIAttribute> e : attributesBefore.entrySet()) { System.out.println("*- b4 |" + e.getKey() + "->" + e.getValue().getDjValue()); } CmsUtil util = new CmsUtil(); dumpMaps(cloudVars, globalVars, localVars); dumpCmsCIAttributes(ci); util.processAllVars(ci, cloudVars, globalVars, localVars); dumpCmsCIAttributes(ci); for (Entry<String, CmsCIAttribute> a : ci.getAttributes().entrySet()) { String djKey = a.getKey(); String djAfter = a.getValue().getDjValue(); System.out.println("*after k>" + djKey + " v->" + djAfter); if (djKey.equals(nameOfAttribute)) { assertEquals(djAfter, "duolc"); } } }
@Test(priority = 140) /** * test multi resolution as in artifacts usage * $OO_LOCAL{groupId}:$OO_LOCAL{artifactId}:$OO_LOCAL{extension} */ public void processLocalVarDemo() { Map<String, String> cloudVars = new HashMap<String, String>(3); cloudVars.put("version", "2.0"); Map<String, String> globalVars = new HashMap<String, String>(3); globalVars.put("version", "$OO_CLOUD{version}"); Map<String, String> localVars = new HashMap<String, String>(3); localVars.put("groupId", "esb"); localVars.put("artifactId", "service"); CmsCI ci = new CmsCI(); ci.setCiId(140); ci.setCiName("processLocalVarDemo"); Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(2); CmsCIAttribute attrL = new CmsCIAttribute(); attrL.setDjValue("$OO_LOCAL{groupId}:$OO_LOCAL{artifactId}:$OO_GLOBAL{version}"); String nameOfAttribute = "myArtifactGav"; attributes.put(nameOfAttribute, attrL); ci.setAttributes(attributes); Map<String, CmsCIAttribute> attributesBefore = ci.getAttributes(); for (Entry<String, CmsCIAttribute> e : attributesBefore.entrySet()) { System.out.println("*- b4 |" + e.getKey() + "->" + e.getValue().getDjValue()); } CmsUtil util = new CmsUtil(); dumpMaps(cloudVars, globalVars, localVars); dumpCmsCIAttributes(ci); util.processAllVars(ci, cloudVars, globalVars, localVars); dumpCmsCIAttributes(ci); for (Entry<String, CmsCIAttribute> a : ci.getAttributes().entrySet()) { String djKey = a.getKey(); String djAfter = a.getValue().getDjValue(); System.out.println("*after k>" + djKey + " v->" + djAfter); if (djKey.equals(nameOfAttribute)) { assertEquals(djAfter, "esb:service:2.0"); } } }
@Test(priority = 111) /** test a composite var , one of each layer */ public void processLocalVarMixed() { Map<String, String> cloudVars = new HashMap<String, String>(3); cloudVars.put("myCloud", "987654"); Map<String, String> globalVars = new HashMap<String, String>(3); globalVars.put("myGlobal", "1212"); Map<String, String> localVars = new HashMap<String, String>(3); localVars.put("myLocal", "8989"); CmsCI ci = new CmsCI(); ci.setCiId(111); ci.setCiName("processLocalVarMixed"); Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(2); CmsCIAttribute attrL = new CmsCIAttribute(); attrL.setDjValue( "/preamble/$OO_CLOUD{myCloud}/middle/$OO_GLOBAL{myGlobal}/sss/$OO_LOCAL{myLocal}"); String nameOfAttribute = "myMixedAttribute"; attributes.put(nameOfAttribute, attrL); ci.setAttributes(attributes); Map<String, CmsCIAttribute> attributesBefore = ci.getAttributes(); for (Entry<String, CmsCIAttribute> e : attributesBefore.entrySet()) { System.out.println("*- b4 |" + e.getKey() + "->" + e.getValue().getDjValue()); } CmsUtil util = new CmsUtil(); dumpMaps(cloudVars, globalVars, localVars); dumpCmsCIAttributes(ci); util.processAllVars(ci, cloudVars, globalVars, localVars); dumpCmsCIAttributes(ci); for (Entry<String, CmsCIAttribute> a : ci.getAttributes().entrySet()) { String djKey = a.getKey(); String djAfter = a.getValue().getDjValue(); System.out.println("*after k>" + djKey + " v->" + djAfter); if (djKey.equals(nameOfAttribute)) { assertEquals(djAfter, "/preamble/987654/middle/1212/sss/8989"); } } }
@Test /** test that a global value can refer to a cloud variable */ public void processGlobalValueWithCloudValueResolution() { String[] cloudValues = new String[] {"czat", "czitCCC"}; String[] globalValues = new String[] {"czit"}; // map to czitCCC in cloud // -cloud variables are just the variable name set to upper case Map<String, String> cloudVars = new HashMap<String, String>(3); for (String val : cloudValues) { cloudVars.put(val, val.toUpperCase()); } logger.info("cloud values have been set too: " + cloudVars); Map<String, String> globalVars = new HashMap<String, String>(3); for (String val : globalValues) { globalVars.put( val, "$OO_CLOUD{" + val + "CCC}" // is a reference to a cloud variable ); } logger.info("globalVars values have been set too: " + globalVars); CmsCI ci = new CmsCI(); ci.setCiId(9876); ci.setCiName("processGlobalValueWithCloudValueResolution"); Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(cloudValues.length * 3); /// set up the ci with attributes which each need replacing... int i = 0; for (String cloudVariable : cloudValues) { // 3 cloud vars CmsCIAttribute attrC = new CmsCIAttribute(); attrC.setDjValue("$OO_CLOUD{" + cloudVariable + "}"); attributes.put("cloud_" + (++i), attrC); } for (String globalVariable : globalValues) { // 3 globals CmsCIAttribute attrG = new CmsCIAttribute(); attrG.setDjValue("$OO_GLOBAL{" + globalVariable + "}"); attrG.setAttributeName("djdj"); attributes.put("global_" + (++i), attrG); } ci.setAttributes(attributes); logger.info("CI Attributes have been set into the ci, attrs: " + attributes); Map<String, CmsCIAttribute> attributesBefore = ci.getAttributes(); for (Entry<String, CmsCIAttribute> e : attributesBefore.entrySet()) { System.out.println("*- b4 |" + e.getKey() + "->" + e.getValue().getDjValue()); } CmsUtil util = new CmsUtil(); dumpMaps(cloudVars, globalVars, null); dumpCmsCIAttributes(ci); util.processAllVars(ci, cloudVars, globalVars, new HashMap<String, String>()); dumpCmsCIAttributes(ci); for (Entry<String, CmsCIAttribute> a : ci.getAttributes().entrySet()) { String djKey = a.getKey(); String djAfter = a.getValue().getDjValue(); System.out.println("after>" + djKey + "->" + djAfter); if (djKey.startsWith("cloud_")) { String expected = attributesBefore .get(djKey) .getDjValue() .replace("OO_CLOUD{", "") .replace("}", "") .toUpperCase(); assertEquals(djAfter, expected, "did not measure up for key " + djKey); } else { if (djKey.startsWith("global_")) { String expected = attributesBefore .get(djKey) .getDjValue() .replace("OO_GLOBAL{", "") .replace("}", "") .toUpperCase(); assertEquals(djAfter, expected, "did not measure up for key " + djKey); } } } }
private String getPlatNameAndVersion(CmsCI plat) { return plat.getCiName() + ":" + plat.getAttribute("major_version").getDjValue(); }
private void dumpCmsCIAttributes(CmsCI ci) { for (CmsCIAttribute manifestAttr : ci.getAttributes().values()) { System.out.println("~Ci_Dj :" + manifestAttr.getDjValue()); } }
@Override public long generateEnvManifest(long envId, String userId, Map<String, String> platModes) { long t1 = System.currentTimeMillis(); String oldThreadName = Thread.currentThread().getName(); Thread.currentThread().setName(getProcessingThreadName(oldThreadName, envId)); List<CmsCIRelation> assemblyRels = cmProcessor.getToCIRelations(envId, BASE_REALIZED_IN, null, ACCOUNT_ASSEMBLY); CmsCI assembly = getAssembly(envId, assemblyRels); CmsCI env = getEnv(envId); String nsPath = getManifestNsPath(env); // check for openRelease check4OpenRelease(env, nsPath); Long nsId = trUtil.verifyAndCreateNS(nsPath); logger.info("Created nsId " + nsId); List<CmsCIRelation> designPlatRels = cmProcessor.getFromCIRelations(assembly.getCiId(), null, "ComposedOf", CATALOG_PLATFORM); // we need to reset all pending deletions cis just in case there was one added back cmProcessor.resetDeletionsByNs(nsPath); // check for edge case scenario when there is new design platform with the same name as old one // but different pack long releaseId = checkPlatformPackCompliance(designPlatRels, env, nsPath, userId); if (releaseId > 0) { // stop any processing and return new release id return releaseId; } final CountDownLatch latch = new CountDownLatch(designPlatRels.size()); List<Future<DesignCIManifestRfcTouple>> submittedFutureTasks = new ArrayList<>(); for (CmsCIRelation platRelation : designPlatRels) { String availMode = getPlatformAvailabiltyMode(platModes, platRelation); Future<DesignCIManifestRfcTouple> future = executorService.submit( new ManifestRfcProcessorTask(env, nsPath, userId, availMode, latch, platRelation)); submittedFutureTasks.add(future); } boolean allPlatsProcessed; try { allPlatsProcessed = latch.await( timeoutInMilliSeconds, TimeUnit .MILLISECONDS); // wait for all platform processing threads to finish with timeout // of 10 mins if (!allPlatsProcessed) { logger.error( "All platforms not processed within timeout duration of " + timeoutInMilliSeconds); throw new TransistorException( CmsError.TRANSISTOR_OPEN_MANIFEST_RELEASE, "Failed to pull latest design for all platform within timeout duration of " + timeoutInMilliSeconds + " millis"); } } catch (InterruptedException ie) { for (Future<DesignCIManifestRfcTouple> job : submittedFutureTasks) { job.cancel(true); } throw new TransistorException( CmsError.TRANSISTOR_OPEN_MANIFEST_RELEASE, "Design pull process interrupted. "); } Map<Long, CmsRfcCI> design2manifestPlatMap = new HashMap<>(); for (Future<DesignCIManifestRfcTouple> task : submittedFutureTasks) { DesignCIManifestRfcTouple touple; try { touple = task.get(); processPlatformRfcs(touple.manifestPlatformRfcs, userId); CmsRfcCI manifestPlatformRfc = touple.manifestPlatformRfcs.getManifestPlatformRfc(); logger.info( "Finished working on =" + manifestPlatformRfc.getNsPath() + " release id = " + manifestPlatformRfc.getReleaseId()); design2manifestPlatMap.put(touple.designPlatCI, manifestPlatformRfc); } catch (Exception e) { logger.error("Error in pulling latest design for all platforms ", e); throw new TransistorException( CmsError.TRANSISTOR_OPEN_MANIFEST_RELEASE, "Error in pulling latest design for all platforms "); } } check4MissingServices(design2manifestPlatMap); // now we need to process linkedTo relations manifestRfcProcessor.processLinkedTo(design2manifestPlatMap, nsPath, userId); // now lets delete old existing plats that do not exists in new manifest manifestRfcProcessor.processDeletedPlatforms( design2manifestPlatMap.values(), env, nsPath, userId); // process global variables from design manifestRfcProcessor.processGlobalVars(assembly.getCiId(), env, nsPath, userId); long t2 = System.currentTimeMillis(); long envReleaseId = populateParentRelease(env, nsPath); logger.info( "Pull design for " + nsPath + " completed in " + (t2 - t1) + " millis (releaseId " + envReleaseId + ")"); return envReleaseId; }
@Override public long generateEnvManifest(long envId, String userId, Map<String, String> platModes) { long t1 = System.currentTimeMillis(); String oldThreadName = Thread.currentThread().getName(); Thread.currentThread().setName(getProcessingThreadName(oldThreadName, envId)); List<CmsCIRelation> assemblyRels = cmProcessor.getToCIRelations(envId, BASE_REALIZED_IN, null, ACCOUNT_ASSEMBLY); CmsCI assembly = null; if (assemblyRels.size() > 0) { assembly = assemblyRels.get(0).getFromCi(); } else { String error = "Can not get assembly for envId = " + envId; logger.error(error); throw new TransistorException(CmsError.TRANSISTOR_CANNOT_GET_ASSEMBLY, error); } CmsCI env = getEnv(envId); String nsPath = env.getNsPath() + "/" + env.getCiName() + "/manifest"; if (hasOpenManifestRelease(nsPath)) { String message = "This environment has an open release. It needs to be discarded or committed before the design pull: " + env.getNsPath() + "/" + env.getCiName(); logger.info(message); throw new TransistorException(CmsError.TRANSISTOR_OPEN_MANIFEST_RELEASE, message); } Long nsId = trUtil.verifyAndCreateNS(nsPath); logger.info("Created nsId " + nsId); // Long releaseId = createManifestRelease(nsPath,userId); List<CmsCIRelation> designPlatRels = cmProcessor.getFromCIRelations(assembly.getCiId(), null, "ComposedOf", CATALOG_PLATFORM); // we need to reset all pending deletions cis just in case there was one added back cmProcessor.resetDeletionsByNs(nsPath); // check for edge case scenario when there is new design platform with the same name as old one // but different pack long releaseId = checkPlatformPackCompliance(designPlatRels, env, nsPath, userId); if (releaseId > 0) { // stop any processing and return new release id return releaseId; } final CountDownLatch latch = new CountDownLatch(designPlatRels.size()); List<Future<DesignCIManifestRfcTouple>> submittedFutureTasks = new ArrayList<Future<DesignCIManifestRfcTouple>>(); Map<Long, CmsRfcCI> design2manifestPlatMap = new HashMap<Long, CmsRfcCI>(); for (CmsCIRelation platRelation : designPlatRels) { String availMode = null; if (platModes != null) { availMode = platModes.get(String.valueOf(platRelation.getToCiId())); if (availMode != null && availMode.length() == 0) { availMode = "default"; } } Future<DesignCIManifestRfcTouple> future = executorService.submit( new ManifestRfcProcessorTask(env, nsPath, userId, availMode, latch, platRelation)); submittedFutureTasks.add(future); } boolean allPlatsProcessed = false; try { // latch.await(); //wait till all platform processing threads return allPlatsProcessed = latch.await( timeoutInMilliSeconds, TimeUnit .MILLISECONDS); // wait for all platform processing threads to finish with timeout // of 10 mins if (!allPlatsProcessed) { logger.error( "All platforms not processed within timeout duration of " + timeoutInMilliSeconds); throw new TransistorException( CmsError.TRANSISTOR_OPEN_MANIFEST_RELEASE, "Failed to pull latest design for all platform within timeout duration of " + timeoutInMilliSeconds + " millis"); } } catch (InterruptedException ie) { for (Future<DesignCIManifestRfcTouple> job : submittedFutureTasks) { job.cancel(true); } throw new TransistorException( CmsError.TRANSISTOR_OPEN_MANIFEST_RELEASE, "Design pull process interrupted. "); } for (Future<DesignCIManifestRfcTouple> task : submittedFutureTasks) { DesignCIManifestRfcTouple touple; try { touple = task.get(); processPlatformRfcs(touple.manifestPlatformRfcs, userId); CmsRfcCI manifestPlatformRfc = touple.manifestPlatformRfcs.getManifestPlatformRfc(); Set<String> missingSrvs = cloudUtil.getMissingServices(manifestPlatformRfc.getCiId()); if (missingSrvs.size() > 0) { logger.info( ">>>>> Not all services available for platform: " + manifestPlatformRfc.getCiName() + ", the missing services: " + missingSrvs.toString()); disablePlatform(manifestPlatformRfc.getCiId(), userId); } logger.info("New release id = " + manifestPlatformRfc.getReleaseId()); logger.info("Done working on platform " + manifestPlatformRfc.getNsPath()); design2manifestPlatMap.put(touple.designPlatCI, manifestPlatformRfc); } catch (Exception e) { logger.error("Error in pulling latest design for all platforms ", e); throw new TransistorException( CmsError.TRANSISTOR_OPEN_MANIFEST_RELEASE, "Error in pulling latest design for all platforms "); } } // now we need to process linkedTo relations manifestRfcProcessor.processLinkedTo(design2manifestPlatMap, nsPath, userId); // now lets delete old existing plats that do not exists in new manifest manifestRfcProcessor.processDeletedPlatforms( design2manifestPlatMap.values(), env, nsPath, userId); // process global variables from design manifestRfcProcessor.processGlobalVars(assembly.getCiId(), env, nsPath, userId); long t2 = System.currentTimeMillis(); long envReleaseId = populateParentRelease(env, nsPath); logger.info( "Pull design for " + nsPath + " completed in " + (t2 - t1) + " millis (releaseId " + envReleaseId + ")"); return envReleaseId; }
@Test /** * substitute cloud , global and local variables where each is simply a variable easy test to pass */ public void processAllVarsTest() { String[] cloudValues = new String[] {"cbar", "cfoo", "cbaz"}; String[] globalValues = new String[] {"gbat", "gfee", "gbiz"}; String[] localValues = new String[] {"lbaz", "lfuu", "lbuz"}; // -cloud variables are just the variable name set to upper case Map<String, String> cloudVars = new HashMap<String, String>(3); for (String val : cloudValues) { cloudVars.put(val, val.toUpperCase()); } logger.info("cloud values have been set too: " + cloudVars); Map<String, String> globalVars = new HashMap<String, String>(3); for (String val : globalValues) { globalVars.put(val, val.toUpperCase()); } logger.info("globalVars values have been set too: " + globalVars); Map<String, String> localVars = new HashMap<String, String>(3); for (String val : localValues) { localVars.put(val, val.toUpperCase()); } logger.info("local values have been set too: " + localVars); CmsCI ci = new CmsCI(); ci.setCiId(4444); ci.setCiName("processAllVarsTest"); Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(cloudValues.length * 3); /// set up the ci with attributes which each need replacing... int i = 0; for (String cloudVariable : cloudValues) { // 3 cloud vars CmsCIAttribute attrC = new CmsCIAttribute(); attrC.setDjValue("$OO_CLOUD{" + cloudVariable + "}"); attrC.setAttributeName("pav1"); attributes.put("cloud_" + (++i), attrC); } for (String globalVariable : globalValues) { // 3 globals CmsCIAttribute attrH = new CmsCIAttribute(); attrH.setDjValue("$OO_GLOBAL{" + globalVariable + "}"); attrH.setAttributeName("pav2"); attributes.put("global_" + (++i), attrH); } for (String localVariable : localValues) { // 3 locals CmsCIAttribute attrI = new CmsCIAttribute(); attrI.setDjValue("$OO_LOCAL{" + localVariable + "}"); attrI.setAttributeName("pav3"); attributes.put("local_" + (++i), attrI); } ci.setAttributes(attributes); logger.info("CI Attributes have been set into the ci, attrs: " + attributes); Map<String, CmsCIAttribute> attributesBefore = ci.getAttributes(); for (Entry<String, CmsCIAttribute> e : attributesBefore.entrySet()) { System.out.println("*- b4 |" + e.getKey() + "->" + e.getValue().getDjValue()); } CmsUtil util = new CmsUtil(); dumpMaps(cloudVars, globalVars, localVars); dumpCmsCIAttributes(ci); util.processAllVars(ci, cloudVars, globalVars, localVars); dumpCmsCIAttributes(ci); for (Entry<String, CmsCIAttribute> a : ci.getAttributes().entrySet()) { String djKey = a.getKey(); String djAfter = a.getValue().getDjValue(); System.out.println("after>" + djKey + "->" + djAfter); if (djKey.startsWith("cloud_")) { String expected = attributesBefore .get(djKey) .getDjValue() .replace("OO_CLOUD{", "") .replace("}", "") .toUpperCase(); assertEquals(djAfter, expected, "did not measure up for key " + djKey); } else { if (djKey.startsWith("global_")) { String expected = attributesBefore .get(djKey) .getDjValue() .replace("OO_GLOBAL{", "") .replace("}", "") .toUpperCase(); assertEquals(djAfter, expected, "did not measure up for key " + djKey); } else { if (djKey.startsWith("local_")) { String expected = attributesBefore .get(djKey) .getDjValue() .replace("OO_LOCAL{", "") .replace("}", "") .toUpperCase(); assertEquals(djAfter, expected, "did not measure up for key " + djKey); } } } } }
@Test /** test that local variable can refer to a global variable value */ public void processLocalValueWithGlobalValueResolution() { String[] globalValues = new String[] {"ggyp-Global"}; // - global variables' values are just the variable name set to upper case Map<String, String> globalVars = new HashMap<String, String>(3); for (String val : globalValues) { globalVars.put(val, val.toUpperCase()); } System.out.println("globalVars values have been set to : " + globalVars); Map<String, String> localVars = new LinkedHashMap<String, String>(2); localVars.put("myLocalScalar", "abcdefg"); localVars.put( "myLocalVariable", // one local variable refers to global "$OO_GLOBAL{ggyp-Global}" // is a reference to the global variable ); System.out.println("localVars values have been set too: " + localVars); CmsCI ci = new CmsCI(); ci.setCiId(135791113); ci.setCiName("processLocalValueWithGlobalValueResolution"); Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(2); /// set up the ci with attributes which each need replacing... int i = 0; CmsCIAttribute attrL = new CmsCIAttribute(); attrL.setDjValue("$OO_LOCAL{myLocalVariable}"); attrL.setAttributeName("pl11"); attributes.put("l81_" + (++i), attrL); CmsCIAttribute attrL2 = new CmsCIAttribute(); attrL2.setDjValue("$OO_LOCAL{myLocalScalar}"); attrL2.setAttributeName("pl22"); attributes.put("l82_" + (++i), attrL2); ci.setAttributes(attributes); System.out.println( "*****CI Attributes have been set into the ci, attrs: " + attributes.values()); Map<String, CmsCIAttribute> attributesBefore = ci.getAttributes(); for (Entry<String, CmsCIAttribute> e : attributesBefore.entrySet()) { System.out.println("*- b4 |" + e.getKey() + "->" + e.getValue().getDjValue()); } CmsUtil util = new CmsUtil(); dumpMaps(null, globalVars, localVars); dumpCmsCIAttributes(ci); util.processAllVars(ci, new HashMap<String, String>(), globalVars, localVars); dumpCmsCIAttributes(ci); for (Entry<String, CmsCIAttribute> a : ci.getAttributes().entrySet()) { String djKey = a.getKey(); String djAfter = a.getValue().getDjValue(); System.out.println("after>" + djKey + "->" + djAfter); if (djKey.startsWith("global_")) { String expected = attributesBefore .get(djKey) .getDjValue() .replace("OO_GLOBAL{", "") .replace("}", "") .toUpperCase(); assertEquals(djAfter, expected, "did not measure up for key " + djKey); } else { if (djKey.startsWith("local_")) { String expected = attributesBefore .get(djKey) .getDjValue() .replace("OO_LOCAL{", "") .replace("}", "") .toUpperCase(); assertEquals(djAfter, expected, "did not measure up for key " + djKey); } } } }
@Test(priority = 89) /** * test that 1 local variable can refer to a global variable (g2) which in turn refers to a Cloud * variable (c2) while another (justX) is both in Cloud and Global variable */ public void processLocalValueWithGlobalAndCloudValueResolution() { // Variables for cloud, global, and locals Map<String, String> cloudVars = new HashMap<String, String>(3); cloudVars.put("justX", "ca"); cloudVars.put("p2", "cb"); Map<String, String> globalVars = new HashMap<String, String>(3); globalVars.put("justX", "ga"); globalVars.put("p2", "$OO_CLOUD{p2}"); Map<String, String> localVars = new HashMap<String, String>(3); localVars.put("l1", "$OO_GLOBAL{p2}"); // want 'ca' localVars.put("p2", "$OO_GLOBAL{justX}"); // want 'ga' not 'ca' CmsCI ci = new CmsCI(); ci.setCiId(89); ci.setCiName("processLocalValueWithGlobalAndCloudValueResolution"); Map<String, CmsCIAttribute> attributes = new LinkedHashMap<String, CmsCIAttribute>(2); CmsCIAttribute attrL = new CmsCIAttribute(); attrL.setDjValue("$OO_LOCAL{l1}"); attrL.setAttributeName("fo"); attributes.put("firstOne", attrL); CmsCIAttribute attrL2 = new CmsCIAttribute(); attrL2.setDjValue("$OO_LOCAL{p2}"); attrL2.setAttributeName("SO"); attributes.put("secondOne", attrL2); CmsCIAttribute attrL3 = new CmsCIAttribute(); attrL3.setDjValue("$OO_GLOBAL{p2}"); attrL3.setAttributeName("TO"); attributes.put("thirdOne", attrL3); ci.setAttributes(attributes); System.out.println( "*****CI Attributes have been set into the ci, attrs: " + attributes.values()); Map<String, CmsCIAttribute> attributesBefore = ci.getAttributes(); for (Entry<String, CmsCIAttribute> e : attributesBefore.entrySet()) { System.out.println("*- b4 |" + e.getKey() + "->" + e.getValue().getDjValue()); } CmsUtil util = new CmsUtil(); dumpMaps(cloudVars, globalVars, localVars); dumpCmsCIAttributes(ci); util.processAllVars(ci, cloudVars, globalVars, localVars); dumpCmsCIAttributes(ci); for (Entry<String, CmsCIAttribute> a : ci.getAttributes().entrySet()) { String djKey = a.getKey(); String djAfter = a.getValue().getDjValue(); System.out.println("*after k>" + djKey + " v->" + djAfter); if (djKey.equals("firstOne")) { assertEquals(djAfter, "cb", "firstOne was not resolved correctly, local>global>cloud"); } if (djKey.equals("secondOne")) { assertEquals(djAfter, "ga", "secondOne was not resolved correctly, local>global"); } if (djKey.equals("thirdOne")) { assertEquals(djAfter, "cb", "thirdOne was not resolved correctly, global>cloud"); } } }
private String getManifestNsPath(CmsCI env) { return env.getNsPath() + "/" + env.getCiName() + "/manifest"; }