Package org.apache.aries.application

Examples of org.apache.aries.application.DeploymentMetadata


    Content fbw = new ContentImpl("foo.bar.widgets;version=1.0.0");
    Content mbl = new ContentImpl("my.business.logic;version=1.0.0");
    assertTrue (appContent.contains(fbw));
    assertTrue (appContent.contains(mbl));
   
    DeploymentMetadata dm = app.getDeploymentMetadata();
    List<DeploymentContent> dcList = dm.getApplicationDeploymentContents();

    assertEquals (2, dcList.size());
    DeploymentContent dc1 = new DeploymentContentImpl ("foo.bar.widgets;deployed-version=1.1.0");
    DeploymentContent dc2 = new DeploymentContentImpl ("my.business.logic;deployed-version=1.1.0");
    DeploymentContent dc3 = new DeploymentContentImpl ("a.handy.persistence.library;deployed-version=1.1.0");
    assertTrue (dcList.contains(dc1));
    assertTrue (dcList.contains(dc2));
   
    dcList = dm.getApplicationProvisionBundles();
   
    assertEquals(1, dcList.size());
    assertTrue (dcList.contains(dc3));

  }
View Full Code Here


      Content fbw = new ContentImpl("hello.world.jar;version=\"[1.1.0, 1.1.0]\"");
      Content mbl = new ContentImpl("helloWorld.war;version=\"[0.0.0, 0.0.0]\"");
      assertTrue (appContent.contains(fbw));
      assertTrue (appContent.contains(mbl));
     
      DeploymentMetadata dm = app.getDeploymentMetadata();
      List<DeploymentContent> dcList = dm.getApplicationDeploymentContents();

      assertEquals (2, dcList.size());
      DeploymentContent dc1 = new DeploymentContentImpl ("hello.world.jar;deployed-version=1.1.0");
      DeploymentContent dc2 = new DeploymentContentImpl ("helloWorld.war;deployed-version=0.0.0");
      DeploymentContent dc3 = new DeploymentContentImpl ("a.handy.persistence.library;deployed-version=1.1.0");
      assertTrue (dcList.contains(dc1));
      assertTrue (dcList.contains(dc2));
     
      dcList = dm.getApplicationProvisionBundles();
     
      assertEquals(1, dcList.size());
      assertTrue (dcList.contains(dc3));
     
      assertEquals(2, app.getBundleInfo().size());
View Full Code Here

    assertNotNull (ifile);
    ifile = storedEba.getFile ("my.business.logic.jar");
    assertNotNull (ifile);
   
    AriesApplication newApp = _appMgr.createApplication(storedEba);
    DeploymentMetadata dm = newApp.getDeploymentMetadata();
    assertEquals (2, dm.getApplicationDeploymentContents().size());
    assertEquals(1, dm.getApplicationProvisionBundles().size());
    assertEquals (dm.getApplicationSymbolicName(), app.getApplicationMetadata().getApplicationSymbolicName());
    assertEquals (dm.getApplicationVersion(), app.getApplicationMetadata().getApplicationVersion());
  }
View Full Code Here

 
  @Test
  public void testUpdate() throws Exception {
    AriesApplication app = createApplication(TEST_EBA);

    DeploymentMetadata depMf = createUpdateDepMf();
   
    AriesApplicationContextManager ctxMgr = Skeleton.newMock(AriesApplicationContextManager.class);
    _appMgr.setApplicationContextManager(ctxMgr);

    _appMgr.update(app, depMf);
View Full Code Here

  @Test(expected=IllegalArgumentException.class)
  public void testUpdateWithIncorrectDepMf() throws Exception
  {
    AriesApplication app = createApplication(TEST_EBA);

    DeploymentMetadata depMf = Skeleton.newMock(DeploymentMetadata.class);
    Skeleton.getSkeleton(depMf).setReturnValue(new MethodCall(DeploymentMetadata.class, "getApplicationSymbolicName"), "random.app");
    Skeleton.getSkeleton(depMf).setReturnValue(new MethodCall(DeploymentMetadata.class, "getApplicationVersion"), new Version("1.0.0"));
   
    AriesApplicationContextManager ctxMgr = Skeleton.newMock(AriesApplicationContextManager.class);
    _appMgr.setApplicationContextManager(ctxMgr);
View Full Code Here

 
  @Test
  public void testFailedUpdate() throws Exception {
    AriesApplication app = createApplication(TEST_EBA);

    DeploymentMetadata depMf = createUpdateDepMf();
   
    AriesApplicationContext ctx = Skeleton.newMock(AriesApplicationContext.class);
    Skeleton.getSkeleton(ctx).setReturnValue(new MethodCall(AriesApplicationContext.class, "getApplication"), app);
   
    AriesApplicationContextManager ctxMgr = Skeleton.newMock(AriesApplicationContextManager.class);
View Full Code Here

 
  @Test
  public void testRolledbackUpdate() throws Exception {
    AriesApplication app = createApplication(TEST_EBA);

    DeploymentMetadata depMf = createUpdateDepMf();
    DeploymentMetadata oldMf = app.getDeploymentMetadata();
   
    AriesApplicationContext ctx = Skeleton.newMock(AriesApplicationContext.class);
    Skeleton.getSkeleton(ctx).setReturnValue(new MethodCall(AriesApplicationContext.class, "getApplication"), app);
   
    AriesApplicationContextManager ctxMgr = Skeleton.newMock(AriesApplicationContextManager.class);
View Full Code Here

    }
  }
 
  private DeploymentMetadata createUpdateDepMf()
  {
    DeploymentMetadata depMf = Skeleton.newMock(DeploymentMetadata.class);
    Skeleton.getSkeleton(depMf).setReturnValue(new MethodCall(DeploymentMetadata.class, "getApplicationSymbolicName"), "org.apache.aries.application.management.test");
    Skeleton.getSkeleton(depMf).setReturnValue(new MethodCall(DeploymentMetadata.class, "getApplicationVersion"), new Version("1.0.0"));

    return depMf;
  }
View Full Code Here

  /**
   * Create an AriesApplication from a .eba file: a zip file with a '.eba' extension
   */
  public AriesApplication createApplication(IDirectory ebaFile) throws ManagementException {
    ApplicationMetadata applicationMetadata = null;
    DeploymentMetadata deploymentMetadata = null;
    Map<String, BundleConversion> modifiedBundles = new HashMap<String, BundleConversion>();
    AriesApplicationImpl application = null;
    String appPath = ebaFile.toString();
    try {  
      // try to read the app name out of the application.mf
      Manifest applicationManifest = parseApplicationManifest (ebaFile);
      String appName = applicationManifest.getMainAttributes().getValue(AppConstants.APPLICATION_NAME);

      //If the application name is null, we will try to get the file name.
      if (appName == null || appName.isEmpty()) {
          String fullPath = appPath;
          if (fullPath.endsWith("/")) {
            fullPath = fullPath.substring(0, fullPath.length() -1)
          }
             
          int last_slash = fullPath.lastIndexOf("/");
          appName = fullPath.substring(last_slash + 1, fullPath.length());
      }
                 
      IFile deploymentManifest = ebaFile.getFile(AppConstants.DEPLOYMENT_MF);
      /* We require that all other .jar and .war files included by-value be valid bundles
       * because a DEPLOYMENT.MF has been provided. If no DEPLOYMENT.MF, migrate
       * wars to wabs, plain jars to bundles
       */
      Set<BundleInfo> extraBundlesInfo = new HashSet<BundleInfo>();
      for (IFile f : ebaFile) {
        if (f.isDirectory()) {
          continue;
        }
        BundleManifest bm = getBundleManifest (f);
        if (bm != null) {
          if (bm.isValid()) {
            _logger.debug("File {} is a valid bundle. Adding it to bundle list.", f.getName());
            extraBundlesInfo.add(new SimpleBundleInfo(bm, f.toURL().toExternalForm()));
          } else if (deploymentManifest == null) {
            _logger.debug("File {} is not a valid bundle. Attempting to convert it.", f.getName());
            // We have a jar that needs converting to a bundle, or a war to migrate to a WAB
            // We only do this if a DEPLOYMENT.MF does not exist.
            BundleConversion convertedBinary = null;
            Iterator<BundleConverter> converters = _bundleConverters.iterator();
            List<ConversionException> conversionExceptions = Collections.emptyList();
            while (converters.hasNext() && convertedBinary == null) {
              try {
              BundleConverter converter = converters.next();
              _logger.debug("Converting file using {} converter", converter);
                convertedBinary = converter.convert(ebaFile, f);
              } catch (ServiceException sx) {
                // We'll get this if our optional BundleConverter has not been injected.
              } catch (ConversionException cx) {
                conversionExceptions.add(cx);
              }
            }
            if (conversionExceptions.size() > 0) {
              for (ConversionException cx : conversionExceptions) {
                _logger.error("APPMANAGEMENT0004E", new Object[]{f.getName(), appName, cx});
              }
              throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0005E", appName));
            }
            if (convertedBinary != null) {
              _logger.debug("File {} was successfully converted. Adding it to bundle list.", f.getName());
              modifiedBundles.put (f.getName(), convertedBinary);            
              extraBundlesInfo.add(convertedBinary.getBundleInfo());
            } else {
              _logger.debug("File {} was not converted.", f.getName());
            }
          } else {
            _logger.debug("File {} was ignored. It is not a valid bundle and DEPLOYMENT.MF is present", f.getName());
          }
        } else {
          _logger.debug("File {} was ignored. It has no manifest file.", f.getName());
        }
      }
      // if Application-Content header was not specified build it based on the bundles included by value
      if (applicationManifest.getMainAttributes().getValue(AppConstants.APPLICATION_CONTENT) == null) {
          String appContent = buildAppContent(extraBundlesInfo);
          applicationManifest.getMainAttributes().putValue(AppConstants.APPLICATION_CONTENT, appContent);
      }
     
      ManifestDefaultsInjector.updateManifest(applicationManifest, appName, ebaFile);
      applicationMetadata = _applicationMetadataFactory.createApplicationMetadata(applicationManifest);
     
      if (deploymentManifest != null) {
        deploymentMetadata = _deploymentMetadataFactory.parseDeploymentMetadata(deploymentManifest);
       
        // Validate: symbolic names must match
        String appSymbolicName = applicationMetadata.getApplicationSymbolicName();
        String depSymbolicName = deploymentMetadata.getApplicationSymbolicName();
        if (!appSymbolicName.equals(depSymbolicName)) {
          throw new ManagementException (MessageUtil.getMessage("APPMANAGEMENT0002E", appName, appSymbolicName, depSymbolicName));
        }
      }

View Full Code Here

    if (!!!app.getApplicationMetadata().getApplicationSymbolicName().equals(depMf.getApplicationSymbolicName())
        || !!!app.getApplicationMetadata().getApplicationVersion().equals(depMf.getApplicationVersion())) {
      throw new IllegalArgumentException("The deployment metadata does not match the application.");
    }
   
    DeploymentMetadata oldMetadata = app.getDeploymentMetadata();
   
    AriesApplicationContext foundCtx = null;
    for (AriesApplicationContext ctx : _applicationContextManager.getApplicationContexts()) {
      if (ctx.getApplication().equals(app)) {
        foundCtx = ctx;
View Full Code Here

TOP

Related Classes of org.apache.aries.application.DeploymentMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.