use of org.apache.aries.application.modelling.ModelledResource in project aries by apache.
the class DeploymentManifestManagerImpl method findSuspects.
/**
* We've done a sanity check resolve on our sharedBundles and received back
* resolvedSharedBundles. The resolvedSharedBundles should not contain any bundles listed in the isolated bundle list.
* If this is not true, we've found a case of shared bundles depending on isolated bundles.
* This method extracts the name_versions of those bundles in resolvedSharedBundles
* that do not appear in sharedBundles.
* @param resolvedSharedBundles What we got back from the resolver
* @param sharedBundles What we expected to get back from the resolver
* @param appContentBundles The isolated bundles
* @return The isolated bundles depended by the shared bundles
*/
private List<String> findSuspects(Collection<ModelledResource> resolvedSharedBundles, Collection<ModelledResource> sharedBundles, Collection<ModelledResource> appContentBundles) {
_logger.debug(LOG_ENTRY, "findSuspects", new Object[] { resolvedSharedBundles, sharedBundles, appContentBundles });
Set<String> expectedBundles = new HashSet<String>();
Set<String> isolatedBundles = new HashSet<String>();
for (ModelledResource sb : sharedBundles) {
expectedBundles.add(sb.getExportedBundle().getSymbolicName() + "_" + sb.getExportedBundle().getVersion());
}
for (ModelledResource sb : appContentBundles) {
isolatedBundles.add(sb.getExportedBundle().getSymbolicName() + "_" + sb.getExportedBundle().getVersion());
}
List<String> suspects = new ArrayList<String>();
for (ModelledResource mr : resolvedSharedBundles) {
String thisBundle = mr.getExportedBundle().getSymbolicName() + "_" + mr.getExportedBundle().getVersion();
if (!expectedBundles.contains(thisBundle) && (isolatedBundles.contains(thisBundle))) {
suspects.add(thisBundle);
}
}
_logger.debug(LOG_EXIT, "findSuspects", new Object[] { suspects });
return suspects;
}
use of org.apache.aries.application.modelling.ModelledResource in project aries by apache.
the class DeploymentManifestManagerImpl method generateDeploymentManifest.
/**
* Perform provisioning to work out the 'freeze dried list' of the eba
* @param app - Aries application
* @param ResolveConstraint - resolver constraint for limiting the resolving results
* @return manifest the generated deployment manifest
* @throws ResolverException
*/
@Override
public Manifest generateDeploymentManifest(AriesApplication app, ResolveConstraint... constraints) throws ResolverException {
_logger.debug(LOG_ENTRY, "generateDeploymentManifest", new Object[] { app, constraints });
ApplicationMetadata appMetadata = app.getApplicationMetadata();
Collection<ModelledResource> byValueBundles = null;
try {
// find out blueprint information
byValueBundles = getByValueBundles(app);
// find out by value bundles and then by reference bundles
} catch (Exception e) {
throw new ResolverException(e);
}
Collection<Content> bundlesToResolve = new ArrayList<Content>();
bundlesToResolve.addAll(appMetadata.getApplicationContents());
bundlesToResolve.addAll(app.getApplicationMetadata().getUseBundles());
//If we pass in provision bundles (e.g. import deployment manifest sanity check), we add them into our bundlesToResolve set.
// This is because we want to make sure all bundles we passed into resolver the same as what we are going to get from resolver.
List<Content> restrictedReqs = new ArrayList<Content>();
for (ResolveConstraint constraint : constraints) {
Content content = ContentFactory.parseContent(constraint.getBundleName(), constraint.getVersionRange().toString());
restrictedReqs.add(content);
}
DeployedBundles deployedBundles = generateDeployedBundles(appMetadata, byValueBundles, restrictedReqs);
Manifest man = generateDeploymentManifest(appMetadata.getApplicationSymbolicName(), appMetadata.getApplicationVersion().toString(), deployedBundles);
_logger.debug(LOG_EXIT, "generateDeploymentManifest", new Object[] { man });
return man;
}
use of org.apache.aries.application.modelling.ModelledResource in project aries by apache.
the class DeploymentManifestManagerImpl method getByValueBundles.
/**
* Get a list of bundles included by value in this application.
* @param app The Aries Application
* @return a list of by value bundles
* @throws IOException
* @throws InvalidAttributeException
* @throws ModellerException
*/
private Collection<ModelledResource> getByValueBundles(AriesApplication app) throws IOException, InvalidAttributeException, ModellerException {
_logger.debug(LOG_ENTRY, "getByValueBundles", new Object[] { app });
Collection<BundleInfo> bundles = app.getBundleInfo();
Collection<ModelledResource> result = new ArrayList<ModelledResource>();
for (BundleInfo bundleInfo : bundles) {
// find out the eba directory
String bundleLocation = bundleInfo.getLocation();
String bundleFileName = bundleLocation.substring(bundleLocation.lastIndexOf('/') + 1);
// just the portion of root directory excluding !
URL jarUrl = new URL(bundleLocation);
URLConnection jarCon = jarUrl.openConnection();
jarCon.connect();
InputStream in = jarCon.getInputStream();
File dir = getLocalPlatform().getTemporaryDirectory();
File temp = new File(dir, bundleFileName);
OutputStream out = new FileOutputStream(temp);
IOUtils.copy(in, out);
IOUtils.close(out);
result.add(modelledResourceManager.getModelledResource(null, FileSystem.getFSRoot(temp)));
// delete the temp file
temp.delete();
IOUtils.deleteRecursive(dir);
}
_logger.debug(LOG_EXIT, "getByValueBundles", new Object[] { result });
return result;
}
use of org.apache.aries.application.modelling.ModelledResource in project aries by apache.
the class DeploymentGeneratorTest method testResolve.
@Test
public void testResolve() throws Exception {
Skeleton.getSkeleton(appMetadata).setReturnValue(new MethodCall(ApplicationMetadata.class, "getApplicationContents"), Arrays.asList(mockContent("aries.test.a", "1.0.0"), mockContent("aries.test.b", "[1.0.0, 2.0.0)")));
Skeleton.getSkeleton(appMetadata).setReturnValue(new MethodCall(ApplicationMetadata.class, "getUseBundles"), Arrays.asList(BUNDLE_C, BUNDLE_D));
DeployedBundles deployedBundles = deplMFMgr.generateDeployedBundles(appMetadata, new ArrayList<ModelledResource>(), Collections.<Content>emptyList());
Manifest man = deplMFMgr.generateDeploymentManifest(appMetadata.getApplicationSymbolicName(), appMetadata.getApplicationVersion().toString(), deployedBundles);
Attributes attrs = man.getMainAttributes();
assertEquals("aries.test", attrs.getValue(AppConstants.APPLICATION_SYMBOLIC_NAME));
assertEquals("1.0.0", attrs.getValue(AppConstants.APPLICATION_VERSION));
String content = attrs.getValue(AppConstants.DEPLOYMENT_CONTENT);
String useBundle = attrs.getValue(AppConstants.DEPLOYMENT_USE_BUNDLE);
String provisioned = attrs.getValue(AppConstants.DEPLOYMENT_PROVISION_BUNDLE);
assertTrue(content.contains("aries.test.a;deployed-version=1.0.0"));
assertTrue(content.contains("aries.test.b;deployed-version=1.1.0"));
assertTrue(useBundle.contains("aries.test.c;deployed-version=1.0.5"));
assertFalse(useBundle.contains("aries.test.d"));
assertTrue(provisioned.contains("aries.test.e;deployed-version=1.0.0"));
}
use of org.apache.aries.application.modelling.ModelledResource in project aries by apache.
the class DeploymentManifestManagerImpl method createFakeBundle.
// create a 'mock' bundle that does nothing but export services required by
// Application-ImportService
private ModelledResource createFakeBundle(Collection<ServiceDeclaration> appImportServices) throws InvalidAttributeException {
_logger.debug(LOG_ENTRY, "createFakeBundle", new Object[] { appImportServices });
Attributes attrs = new Attributes();
attrs.putValue(Constants.BUNDLE_SYMBOLICNAME, FAKE_BUNDLE_NAME);
attrs.putValue(Constants.BUNDLE_VERSION_ATTRIBUTE, "1.0");
attrs.putValue(Constants.BUNDLE_MANIFESTVERSION, "2");
// Build an ExportedService for every Application-ImportService entry
Collection<ExportedService> exportedServices = new ArrayList<ExportedService>();
for (ServiceDeclaration sDec : appImportServices) {
Collection<String> ifaces = Arrays.asList(sDec.getInterfaceName());
Filter filter = sDec.getFilter();
Map<String, String> serviceProperties;
if (filter != null) {
serviceProperties = ManifestHeaderProcessor.parseFilter(filter.toString());
} else {
serviceProperties = new HashMap<String, String>();
}
serviceProperties.put("service.imported", "");
exportedServices.add(modellingManager.getExportedService("", 0, ifaces, new HashMap<String, Object>(serviceProperties)));
}
ModelledResource fakeBundle = modellingManager.getModelledResource(null, attrs, null, exportedServices);
_logger.debug(LOG_EXIT, "createFakeBundle", new Object[] { fakeBundle });
return fakeBundle;
}
Aggregations