/** * Artifact is either retrieved or prepared for later addition to registry * * @param ga * @return */ private GovernanceArtifact addArtifact(RBGGovernanceArtifact ga) { boolean checkChanged = false; boolean isNewer = false; GenericArtifactManager gam = registryFactory.getManagerForArtifactType(ga.getRegistryType()); GenericArtifact fa = (GenericArtifact) findMatchingArtifact(ga); log.info("working on: " + ga.getName()); try { if (fa != null) { isNewer = isVersionNewer(ga.getVersion(), fa.getAttribute("details_version")); checkChanged = updateAttributes(ga, fa); } else { fa = gam.newGovernanceArtifact(new QName(ga.getName())); // artifactname fa.setAttribute("details_version", ga.getVersion()); updateAttributes(ga, fa); gam.addGenericArtifact(fa); handleLifeCycle(ga, fa); } if (isNewer) { if (checkChanged) { gam.updateGenericArtifact(fa); log.info("updated: " + ga.getName()); } handleLifeCycle(ga, fa); } } catch (GovernanceException e) { log.error(e.getMessage()); } catch (RegistryException e) { log.error(e.getMessage()); } return fa; }
private static void deleteServices(Registry govRegistry, String shortName) throws FileNotFoundException, IOException, RegistryException, GovernanceException { BufferedReader bufferedReader = new BufferedReader(new FileReader(rootpath + "resources/" + shortName + "_list.txt")); String artifactName; GenericArtifactManager manager = new GenericArtifactManager(govRegistry, shortName); while ((artifactName = bufferedReader.readLine()) != null) { final String name = artifactName; GenericArtifact[] artifacts = manager.findGenericArtifacts( new GenericArtifactFilter() { @Override public boolean matches(GenericArtifact genericArtifact) throws GovernanceException { return name.equals(genericArtifact.getQName().getLocalPart()); } }); for (GenericArtifact genericArtifact : artifacts) { for (GovernanceArtifact dependency : genericArtifact.getDependencies()) { GovernanceUtils.removeArtifact(govRegistry, dependency.getId()); } GovernanceUtils.removeArtifact(govRegistry, genericArtifact.getId()); } } }
private void processModelContainer(ModelContainer mc) { Map<RBGGovernanceArtifact, GovernanceArtifact> rbgToGen = new HashMap<RBGGovernanceArtifact, GovernanceArtifact>(); Set<RBGGovernanceArtifact> toBeUpated = new HashSet<RBGGovernanceArtifact>(); // create Artifacts: apps, modules, appservices for (Application app : mc.getApplications()) { GovernanceArtifact ga = addArtifact(app); rbgToGen.put(app, ga); } for (Module module : mc.getModules()) { GovernanceArtifact ga = addArtifact(module); rbgToGen.put(module, ga); } for (ApplicationService as : mc.getApplicationServices()) { if (as instanceof HostProgram) { HostProgram hp = (HostProgram) as; GovernanceArtifact ga = addArtifact(hp); rbgToGen.put(as, ga); } } for (Table table : mc.getTables()) { GovernanceArtifact ga = addArtifact(table); rbgToGen.put(table, ga); } for (Infrastructure infra : mc.getInfrastructure()) { GovernanceArtifact ga = addArtifact(infra); rbgToGen.put(infra, ga); } // create Links for (UseRelation ur : mc.getUseRelations()) { GovernanceArtifact ga = rbgToGen.get(ur.getSource()); boolean needsUpdate = createLink(ur, ga); if (needsUpdate) { toBeUpated.add(ur.getSource()); } // CHECK FOR CHANGED VRSION!! } for (CallRelation cr : mc.getCallRelations()) { GovernanceArtifact ga = rbgToGen.get(cr.getSource()); boolean needsUpdate = createLink(cr, ga); if (needsUpdate) { toBeUpated.add(cr.getSource()); } } // update those, which really need it... List<RBGGovernanceArtifact> upds = new ArrayList<RBGGovernanceArtifact>(toBeUpated); for (RBGGovernanceArtifact ra : upds) { GenericArtifact ga = (GenericArtifact) rbgToGen.get(ra); GenericArtifactManager gam = registryFactory.getManagerForArtifactType(ra.getRegistryType()); try { gam.updateGenericArtifact(ga); } catch (GovernanceException e) { log.error("link creation problem addGenericArtifact " + e.getMessage()); } } }
@Test( groups = "wso2.greg", description = "Upload CApp as Service", dependsOnMethods = "cAppWithIncorrectServerRole") public void deployNewCApplication() throws MalformedURLException, RemoteException, ApplicationAdminExceptionException, InterruptedException, RegistryException, ResourceAdminServiceExceptionException, LogViewerLogViewerException { String resourcePath = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "GREG" + File.separator + "car" + File.separator + "wsdl-t_1.0.0.car"; cAppUploader.uploadCarbonAppArtifact( "wsdl-t_1.0.0.car", new DataHandler(new URL("file:///" + resourcePath))); assertTrue( CAppTestUtils.isCAppDeployed(sessionCookie, wsdl_tCapp, adminServiceApplicationAdmin), "Deployed wsdl-t_1.0.0.car not in CApp List"); LogEvent[] logEvents = logViewerClient.getLogs( "INFO", "Successfully Deployed Carbon Application : wsdl-t", "", ""); boolean status = false; for (LogEvent event : logEvents) { if (event.getMessage().contains("Successfully Deployed Carbon Application : wsdl-t")) { status = true; break; } } assertTrue(status, "Log info message for cApp deployment not found"); boolean isService = false; // GovernanceUtils.loadGovernanceArtifacts((UserRegistry) governance); GenericArtifactManager manager = new GenericArtifactManager(governance, "service"); GenericArtifact[] serviceArtifacts = manager.getAllGenericArtifacts(); for (GenericArtifact genericArtifact : serviceArtifacts) { String name = genericArtifact.getQName().getLocalPart(); if (name.equalsIgnoreCase("WeatherForecastService")) { isService = true; break; } } assertTrue(isService); }
@Test( groups = {"wso2.greg"}, description = "edit uri", dependsOnMethods = {"testAddTag"}) public void testEditURI() throws RegistryException { GovernanceUtils.loadGovernanceArtifacts((UserRegistry) governance); GenericArtifactManager artifactManager = new GenericArtifactManager(governance, "uri"); GenericArtifact artifact = artifactManager.getGenericArtifact(uriID); artifact.addAttribute("overview_description", utfString); Assert.assertTrue(artifact.getAttribute("overview_description").equals(utfString)); }
@Test(groups = "wso2.greg", dependsOnMethods = "testAddRxt") public void testAddResourceThroughRxt() throws RegistryException { GovernanceUtils.loadGovernanceArtifacts((UserRegistry) governance); GenericArtifactManager artifactManager = new GenericArtifactManager(governance, "person"); GenericArtifact artifact = artifactManager.newGovernanceArtifact(new QName("testPerson")); artifact.setAttribute("ID", "Person_id"); artifact.setAttribute("Name", "Person_Name"); artifactManager.addGenericArtifact(artifact); assertTrue(artifact.getQName().toString().contains("testPerson"), "artifact name not found"); }
public String addURI(String name, String uri, String type) throws RegistryException { GovernanceUtils.loadGovernanceArtifacts((UserRegistry) governance); GenericArtifactManager artifactManager = new GenericArtifactManager(governance, "uri"); GenericArtifact artifact = artifactManager.newGovernanceArtifact(new QName(name)); artifact.setAttribute("overview_uri", uri); artifact.setAttribute("overview_type", type); artifactManager.addGenericArtifact(artifact); uriID = artifact.getId(); assertTrue(artifact.getAttribute("overview_uri").equals(uri), "artifact URI not found"); assertTrue(artifact.getAttribute("overview_name").equals(name), "artifact name not found"); assertTrue(artifact.getAttribute("overview_type").equals(type), "artifact WSDL not found"); return artifact.getPath(); }
private static void deletePolicies(Registry govRegistry) throws FileNotFoundException, IOException, RegistryException, GovernanceException { GenericArtifactManager manager = new GenericArtifactManager(govRegistry, "policy"); for (int i = 1; i < 23; i++) { final String name = "policy" + i + ".xml"; GenericArtifact[] artifacts = manager.findGenericArtifacts( new GenericArtifactFilter() { @Override public boolean matches(GenericArtifact genericArtifact) throws GovernanceException { return name.equals(genericArtifact.getQName().getLocalPart()); } }); for (GenericArtifact genericArtifact : artifacts) { GovernanceUtils.removeArtifact(govRegistry, genericArtifact.getId()); } } }
private static void addServices(Registry govRegistry) throws RegistryException, XMLStreamException { GenericArtifactManager artifactManager = new GenericArtifactManager(govRegistry, "service"); for (int i = 1; i < 10; i++) { StringBuilder builder = new StringBuilder(); builder.append("<serviceMetaData xmlns=\"http://www.wso2.org/governance/metadata\">"); builder.append("<overview><name>FlightService" + i + "</name><namespace>ns</namespace>"); builder.append("<version>1.0.0-SNAPSHOT</version></overview>"); builder.append("</serviceMetaData>"); org.apache.axiom.om.OMElement XMLContent = AXIOMUtil.stringToOM(builder.toString()); GenericArtifact artifact = artifactManager.newGovernanceArtifact(XMLContent); artifactManager.addGenericArtifact(artifact); } // Services need to be index before search. try { Thread.sleep(2 * 60 * 1000); } catch (InterruptedException e) { e.printStackTrace(); } }
@AfterClass(alwaysRun = true) public void clean() throws Exception { delete(pathPrefix + uriSchemaPath); GovernanceUtils.loadGovernanceArtifacts((UserRegistry) governance); GenericArtifactManager artifactManager = new GenericArtifactManager(governance, "uri"); GenericArtifact[] artifacts = artifactManager.getAllGenericArtifacts(); boolean uriDeleted = true; for (GenericArtifact genericArtifact : artifacts) { if (genericArtifact.getPath().equals(pathPrefix + uriSchemaPath)) { uriDeleted = false; } } Assert.assertTrue(uriDeleted); delete(pathPrefix + uriWsdlPath); delete(pathPrefix + uriGenericPath); delete(pathPrefix + uriPolicyPath); delete("/_system/governance/trunk/services/com/amazon/soap/1.0.0/AmazonSearchService"); userManagementClient.deleteRole(utfString); lifeCycleManagementClient.deleteLifeCycle(LC_NAME); delete("/_system/governance/trunk/endpoints/com/amazon/soap/onca/ep-soap2"); delete("/_system/governance/trunk/endpoints/com"); utfString = null; governance = null; resourceAdminServiceClient = null; uriGenericPath = null; uriPolicyPath = null; uriSchemaPath = null; uriWsdlPath = null; relationAdminServiceClient = null; lifeCycleManagementClient = null; lifeCycleAdminServiceClient = null; wsRegistryServiceClient = null; registryProviderUtil = null; infoServiceAdminClient = null; userManagementClient = null; }
public ByteArrayOutputStream execute(String template, String type) throws IOException { Registry governanceRegistry; try { Registry registry = getRegistry(); governanceRegistry = GovernanceUtils.getGovernanceUserRegistry(registry, CurrentSession.getUser()); GenericArtifactManager suiteArtifactManager = new GenericArtifactManager(governanceRegistry, "suites"); GenericArtifact[] genericArtifacts = suiteArtifactManager.getAllGenericArtifacts(); GenericArtifactManager caseArtifactManager = new GenericArtifactManager(governanceRegistry, "case"); List<TestSuiteReportBean> beanList = new LinkedList<TestSuiteReportBean>(); for (GenericArtifact artifact : genericArtifacts) { TestSuiteReportBean bean = new TestSuiteReportBean(); String[] attributeKeys = artifact.getAttributeKeys(); List<String> testCases = new ArrayList<String>(); for (String key : attributeKeys) { if (key.equals("overview_name")) { String value = artifact.getAttribute(key); bean.setOverview_name(value); } else if (key.equals("overview_version")) { String value = artifact.getAttribute(key); bean.setOverview_version(value); } else if (key.equals("overview_type")) { String value = artifact.getAttribute(key); bean.setOverview_type(value); } if (key.equals("testCases_entry")) { String[] values = artifact.getAttributes(key); for (String value : values) { Resource r = registry.get( RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + value.split(":")[1]); GenericArtifact a = caseArtifactManager.getGenericArtifact(r.getUUID()); testCases.add(a.getAttribute("overview_name")); } } } bean.setTestCases_entry(testCases.toString().replaceAll("[ \\[\\] ]", "")); beanList.add(bean); } String templateContent = new String((byte[]) registry.get(template).getContent()); JRDataSource dataSource = new JRBeanCollectionDataSource(beanList); JasperPrint print = new JasperPrintProvider() .createJasperPrint(dataSource, templateContent, new ReportParamMap[0]); return new ReportStream().getReportStream(print, type.toLowerCase()); } catch (RegistryException e) { log.error("Error while getting the Governance Registry", e); } catch (JRException e) { log.error("Error occured while creating the jasper print ", e); } catch (ReportingException e) { log.error("Error while generating the report", e); } return new ByteArrayOutputStream(0); }
@Test(groups = {"wso2.greg"}) public void testPaginate() throws Exception { try { Registry gov = GovernanceUtils.getGovernanceUserRegistry(registry, "admin"); // Should be load the governance artifact. GovernanceUtils.loadGovernanceArtifacts((UserRegistry) gov); addServices(gov); // Initialize the pagination context. // Top five services, sortBy name , and sort order descending. PaginationContext.init(0, 5, "DES", "overview_name", 100); WSRegistrySearchClient wsRegistrySearchClient = new WSRegistrySearchClient(); // This should be execute to initialize the AttributeSearchService. ConfigurationContext configContext; String axis2Repo = FrameworkPathUtil.getSystemResourceLocation() + "client"; String axis2Conf = FrameworkPathUtil.getSystemResourceLocation() + "axis2config" + File.separator + "axis2_client.xml"; TestFrameworkUtils.setKeyStoreProperties(automationContext); configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem( axis2Repo, axis2Conf); configContext.setProperty(HTTPConstants.CONNECTION_TIMEOUT, TIME_OUT_VALUE); wsRegistrySearchClient.init(cookie, backendURL, configContext); // wsRegistrySearchClient.authenticate(configContext, getServiceURL(), // automationContext.getContextTenant().getContextUser().getUserName(), // automationContext.getContextTenant().getContextUser().getPassword()); // Initialize the GenericArtifactManager GenericArtifactManager artifactManager = new GenericArtifactManager(gov, "service"); Map<String, List<String>> listMap = new HashMap<String, List<String>>(); // Create the search attribute map listMap.put( "lcName", new ArrayList<String>() { { add("ServiceLifeCycle"); } }); listMap.put( "lcState", new ArrayList<String>() { { add("Development"); } }); // Find the results. GenericArtifact[] genericArtifacts = artifactManager.findGenericArtifacts(listMap); assertTrue(genericArtifacts.length > 0, "No any service found"); assertTrue(genericArtifacts.length == 5, "Filtered service count should be 5"); assertTrue( genericArtifacts[0].getQName().getLocalPart().equals("FlightService9"), "filter results are not sorted"); assertTrue( genericArtifacts[4].getQName().getLocalPart().equals("FlightService5"), "filter results are not sorted"); } finally { PaginationContext.destroy(); } }