예제 #1
0
  @Override
  public boolean start(URI uri) {
    final String warName = extractDecodedWarNameFromString(uri.toString());
    String extractionFolderName =
        WebBundleUtils.calculateCorrectSymbolicName(
            extractDecodedWarNameFromString(uri.toString()));
    Bundle bundle = getInstalledBundle(extractionFolderName);
    if (bundle == null) {
      this.eventLogger.log(WARDeployerLogEvents.NANO_STARTING_ERROR, uri);
      logger.error(
          "Cannot start deployable with URI + ["
              + uri
              + "]. There is no bundle installed with this URI.");
      return false;
    }
    StatusFileModificator.deleteStatusFile(warName, this.pickupDir);
    final long lastModified = new File(uri).lastModified();
    this.eventLogger.log(
        WARDeployerLogEvents.NANO_WEB_STARTING, bundle.getSymbolicName(), bundle.getVersion());
    try {
      bundle.start();
    } catch (Exception e) {
      this.eventLogger.log(
          WARDeployerLogEvents.NANO_STARTING_ERROR,
          e,
          bundle.getSymbolicName(),
          bundle.getVersion());
      StatusFileModificator.createStatusFile(
          warName,
          this.pickupDir,
          StatusFileModificator.OP_DEPLOY,
          STATUS_ERROR,
          bundle.getBundleId(),
          lastModified);
      return STATUS_ERROR;
    }
    this.eventLogger.log(
        WARDeployerLogEvents.NANO_WEB_STARTED, bundle.getSymbolicName(), bundle.getVersion());

    // now update bundle's info
    if (!updateBundlesInfo(bundle, getLocationForBundlesInfo(extractionFolderName))) {
      StatusFileModificator.createStatusFile(
          warName,
          this.pickupDir,
          StatusFileModificator.OP_DEPLOY,
          STATUS_ERROR,
          bundle.getBundleId(),
          lastModified);
      return STATUS_ERROR;
    }
    StatusFileModificator.createStatusFile(
        warName,
        this.pickupDir,
        StatusFileModificator.OP_DEPLOY,
        STATUS_OK,
        bundle.getBundleId(),
        lastModified);
    return STATUS_OK;
  }
예제 #2
0
  private final void transformUnpackedManifest(File srcFile, String warName) throws IOException {
    if (srcFile == null) {
      throw new NullPointerException("Source file is null.");
    }
    if (!srcFile.isDirectory() || !srcFile.canRead()) {
      throw new IllegalArgumentException(
          "Source file must be a readable directory [" + srcFile + "].");
    }
    File destFile = new File(srcFile, JarFile.MANIFEST_NAME);
    if (!destFile.exists()) {
      destFile.getParentFile().mkdirs();
      destFile.createNewFile();
    }
    if (!destFile.isFile() || !destFile.canRead()) {
      throw new IllegalArgumentException(
          "Destination file must be a readable file [" + destFile + "].");
    }

    FileOutputStream fos = null;
    InputStream mfIS = null;
    try {
      mfIS = new FileInputStream(srcFile + File.separator + JarFile.MANIFEST_NAME);
      BundleManifest manifest =
          BundleManifestFactory.createBundleManifest(new InputStreamReader(mfIS));
      if (manifest.getModuleType() == null || "web".equalsIgnoreCase(manifest.getModuleType())) {
        boolean strictWABHeaders = getStrictWABHeadersValue();
        if (!strictWABHeaders) {
          manifest.setHeader(HEADER_DEFAULT_WAB_HEADERS, "true");
        }
        manifest.setModuleType(WEB_BUNDLE_MODULE_TYPE);
        InstallationOptions installationOptions =
            prepareInstallationOptions(strictWABHeaders, warName, manifest);
        boolean isWebBundle = WebBundleUtils.isWebApplicationBundle(manifest);
        this.webBundleManifestTransformer.transform(
            manifest, srcFile.toURI().toURL(), installationOptions, isWebBundle);
      } else {
        this.logger.info(
            "Skipping transformation of application '"
                + warName
                + "' because it is already a web bundle.");
        return;
      }
      fos = new FileOutputStream(destFile);
      toManifest(manifest.toDictionary()).write(fos);
    } finally {
      IOUtils.closeQuietly(fos);
      IOUtils.closeQuietly(mfIS);
    }
  }
예제 #3
0
 @Override
 public boolean isDeployed(URI path) {
   final String warName = extractDecodedWarNameFromString(path.toString());
   final File warDir =
       new File(this.webAppsDir, WebBundleUtils.calculateCorrectSymbolicName(warName));
   if (!warDir.exists()) {
     return false;
   }
   if (this.bundleContext.getBundle(
           BundleLocationUtil.createInstallLocation(this.kernelHomeFile, warDir))
       == null) {
     return false;
   }
   return true;
 }
예제 #4
0
 @Override
 public DeploymentIdentity getDeploymentIdentity(URI path) {
   final String warName = extractDecodedWarNameFromString(path.toString());
   final File warDir =
       new File(this.webAppsDir, WebBundleUtils.calculateCorrectSymbolicName(warName));
   if (!warDir.exists()) {
     return null;
   }
   Bundle bundle =
       this.bundleContext.getBundle(
           BundleLocationUtil.createInstallLocation(this.kernelHomeFile, warDir));
   if (bundle == null) {
     return null;
   }
   return new StandardDeploymentIdentity(
       WAR, bundle.getSymbolicName(), bundle.getVersion().toString());
 }
예제 #5
0
  @Override
  public boolean install(URI uri) {
    this.eventLogger.log(WARDeployerLogEvents.NANO_INSTALLING, new File(uri).toString());
    final String warName = extractDecodedWarNameFromString(uri.toString());
    final File deployedFile = new File(uri);
    String extractionFolderName = WebBundleUtils.calculateCorrectSymbolicName(warName);
    final File warDir = new File(this.webAppsDir, extractionFolderName);
    StatusFileModificator.deleteStatusFile(warName, this.pickupDir);
    final long lastModified = deployedFile.lastModified();

    if (!canWrite(uri)) {
      this.logger.error(
          "Cannot open the file "
              + uri
              + " for writing. The configured timeout is "
              + this.largeFileCopyTimeout
              + ".");
      StatusFileModificator.createStatusFile(
          warName,
          this.pickupDir,
          StatusFileModificator.OP_DEPLOY,
          STATUS_ERROR,
          -1L,
          lastModified);
      this.eventLogger.log(WARDeployerLogEvents.NANO_INSTALLING_ERROR, uri);
      return false;
    }
    final Bundle installed;
    try {
      // Extract the war file to the webapps directory. Use always JarUtils.unpackToDestructive.
      try {
        JarUtils.unpackToDestructive(new PathReference(deployedFile), new PathReference(warDir));
      } catch (FatalIOException e) {
        if (UNPACK_TO_DESTRUCTIVE) {
          throw e;
        } else {
          this.logger.warn("Cannot delete directory '" + warDir + "'.", e);
          org.eclipse.virgo.web.war.deployer.IOUtils.extractJar(deployedFile, warDir);
        }
      }
      // make the manifest transformation in the unpacked location
      transformUnpackedManifest(warDir, warName);
      // install the bundle
      installed =
          this.bundleContext.installBundle(
              BundleLocationUtil.createInstallLocation(this.kernelHomeFile, warDir));
      this.eventLogger.log(
          WARDeployerLogEvents.NANO_INSTALLED, installed.getSymbolicName(), installed.getVersion());
    } catch (Exception e) {
      this.eventLogger.log(WARDeployerLogEvents.NANO_INSTALLING_ERROR, e, uri);
      StatusFileModificator.createStatusFile(
          warName,
          this.pickupDir,
          StatusFileModificator.OP_DEPLOY,
          STATUS_ERROR,
          -1L,
          lastModified);
      return false;
    }
    return true;
  }
예제 #6
0
  @Override
  public final boolean update(URI path) {
    final String warName = extractDecodedWarNameFromString(path.toString());
    String extractionFolderName = WebBundleUtils.calculateCorrectSymbolicName(warName);
    final File updatedFile = new File(path);
    final File warDir = new File(this.webAppsDir, extractionFolderName);

    if (!warDir.exists()) {
      this.logger.info("Can't update artifact for path '" + path + "'. It is not deployed.");
    }

    final boolean isOfflineUpdated = isOfflineUpdated(path);

    StatusFileModificator.deleteStatusFile(warName, this.pickupDir);

    final long bundleId = -1L;
    final long lastModified = updatedFile.lastModified();

    if (!canWrite(path)) {
      this.logger.error(
          "Cannot open the file ["
              + path
              + "] for writing. Timeout is ["
              + this.largeFileCopyTimeout
              + "].");
      StatusFileModificator.createStatusFile(
          warName,
          this.pickupDir,
          StatusFileModificator.OP_DEPLOY,
          STATUS_ERROR,
          bundleId,
          lastModified);
      this.eventLogger.log(WARDeployerLogEvents.NANO_UPDATING_ERROR, path);
      return STATUS_ERROR;
    }

    final Bundle bundle =
        this.bundleContext.getBundle(
            BundleLocationUtil.createInstallLocation(this.kernelHomeFile, warDir));
    if (bundle != null) {
      try {
        boolean isLegalState = checkWabState(bundle, isOfflineUpdated);
        if (isLegalState == false) {
          this.eventLogger.log(
              WARDeployerLogEvents.NANO_UPDATE_STATE_ERROR,
              bundle.getSymbolicName(),
              bundle.getVersion());
          StatusFileModificator.createStatusFile(
              warName,
              this.pickupDir,
              StatusFileModificator.OP_DEPLOY,
              STATUS_ERROR,
              bundleId,
              lastModified);
          return STATUS_ERROR;
        }
        wabStates.put(bundle.getSymbolicName(), "");
        bundle.stop();
        if (bundle instanceof BundleHost) {
          BundleClassLoader loader = (BundleClassLoader) ((BundleHost) bundle).getClassLoader();
          loader.close();
        }
        // Extract the war file to the webapps directory. Use always JarUtils.unpackToDestructive.
        try {
          JarUtils.unpackToDestructive(new PathReference(updatedFile), new PathReference(warDir));
        } catch (FatalIOException e) {
          if (UNPACK_TO_DESTRUCTIVE) {
            throw e;
          } else {
            this.logger.warn("Cannot delete directory '" + warDir + "'.", e);
            org.eclipse.virgo.web.war.deployer.IOUtils.extractJar(updatedFile, warDir);
          }
        }
        // make the manifest transformation in the unpacked location
        transformUnpackedManifest(warDir, warName);
        this.eventLogger.log(
            WARDeployerLogEvents.NANO_UPDATING, bundle.getSymbolicName(), bundle.getVersion());
        bundle.update();
        if (this.packageAdmin != null) {
          ((PackageAdminImpl) this.packageAdmin).refreshPackages(new Bundle[] {bundle}, true, null);
          this.logger.info("Update of file with path [" + path + "] is successful.");
        }
        bundle.start();
        this.eventLogger.log(
            WARDeployerLogEvents.NANO_UPDATED, bundle.getSymbolicName(), bundle.getVersion());
      } catch (Exception e) {
        this.eventLogger.log(
            WARDeployerLogEvents.NANO_UPDATE_ERROR,
            e,
            bundle.getSymbolicName(),
            bundle.getVersion());
        StatusFileModificator.createStatusFile(
            warName,
            this.pickupDir,
            StatusFileModificator.OP_DEPLOY,
            STATUS_ERROR,
            bundleId,
            lastModified);
        return STATUS_ERROR;
      }
      StatusFileModificator.createStatusFile(
          warName,
          this.pickupDir,
          StatusFileModificator.OP_DEPLOY,
          STATUS_OK,
          bundleId,
          lastModified);
    } else {
      deploy(path);
    }
    return STATUS_OK;
  }
예제 #7
0
  @Override
  public final boolean deploy(URI path) {
    this.eventLogger.log(WARDeployerLogEvents.NANO_INSTALLING, new File(path).toString());
    final String warName = extractDecodedWarNameFromString(path.toString());
    final File deployedFile = new File(path);
    String extractionFolderName = WebBundleUtils.calculateCorrectSymbolicName(warName);
    final File warDir = new File(this.webAppsDir, extractionFolderName);
    StatusFileModificator.deleteStatusFile(warName, this.pickupDir);

    long bundleId = -1L;
    final long lastModified = deployedFile.lastModified();

    if (!canWrite(path)) {
      this.logger.error(
          "Cannot open the file "
              + path
              + " for writing. The configured timeout is "
              + this.largeFileCopyTimeout
              + ".");
      StatusFileModificator.createStatusFile(
          warName,
          this.pickupDir,
          StatusFileModificator.OP_DEPLOY,
          STATUS_ERROR,
          bundleId,
          lastModified);
      this.eventLogger.log(WARDeployerLogEvents.NANO_INSTALLING_ERROR, path);
      return STATUS_ERROR;
    }
    final Bundle installed;
    try {
      // Extract the war file to the webapps directory. Use always JarUtils.unpackToDestructive.
      try {
        JarUtils.unpackToDestructive(new PathReference(deployedFile), new PathReference(warDir));
      } catch (FatalIOException e) {
        if (UNPACK_TO_DESTRUCTIVE) {
          throw e;
        } else {
          this.logger.warn("Cannot delete directory '" + warDir + "'.", e);
          org.eclipse.virgo.web.war.deployer.IOUtils.extractJar(deployedFile, warDir);
        }
      }
      // make the manifest transformation in the unpacked location
      transformUnpackedManifest(warDir, warName);

      // install the bundle
      installed =
          this.bundleContext.installBundle(
              BundleLocationUtil.createInstallLocation(this.kernelHomeFile, warDir));
    } catch (Exception e) {
      this.eventLogger.log(WARDeployerLogEvents.NANO_INSTALLING_ERROR, e, path);
      StatusFileModificator.createStatusFile(
          warName,
          this.pickupDir,
          StatusFileModificator.OP_DEPLOY,
          STATUS_ERROR,
          bundleId,
          lastModified);
      return STATUS_ERROR;
    }

    this.eventLogger.log(
        WARDeployerLogEvents.NANO_INSTALLED, installed.getSymbolicName(), installed.getVersion());
    this.eventLogger.log(
        WARDeployerLogEvents.NANO_WEB_STARTING,
        installed.getSymbolicName(),
        installed.getVersion());
    try {
      installed.start();
    } catch (Exception e) {
      this.eventLogger.log(
          WARDeployerLogEvents.NANO_STARTING_ERROR,
          e,
          installed.getSymbolicName(),
          installed.getVersion());
      StatusFileModificator.createStatusFile(
          warName,
          this.pickupDir,
          StatusFileModificator.OP_DEPLOY,
          STATUS_ERROR,
          bundleId,
          lastModified);
      return STATUS_ERROR;
    }

    this.eventLogger.log(
        WARDeployerLogEvents.NANO_WEB_STARTED, installed.getSymbolicName(), installed.getVersion());

    bundleId = installed.getBundleId();
    // now update bundle's info
    if (this.logger.isInfoEnabled()) {
      this.logger.info("Bundles info will be updated for war with path '" + path + "'.");
    }

    try {
      if (this.bundleInfosUpdaterUtil != null && this.bundleInfosUpdaterUtil.isAvailable()) {
        BundleInfosUpdater.registerToBundlesInfo(
            installed, getLocationForBundlesInfo(extractionFolderName), NOT_A_FRAGMENT);
      }
    } catch (Exception e) {
      this.eventLogger.log(
          WARDeployerLogEvents.NANO_PERSIST_ERROR,
          e,
          installed.getSymbolicName(),
          installed.getVersion());
      StatusFileModificator.createStatusFile(
          warName,
          this.pickupDir,
          StatusFileModificator.OP_DEPLOY,
          STATUS_ERROR,
          bundleId,
          lastModified);
      return STATUS_ERROR;
    }

    StatusFileModificator.createStatusFile(
        warName,
        this.pickupDir,
        StatusFileModificator.OP_DEPLOY,
        STATUS_OK,
        bundleId,
        lastModified);
    return STATUS_OK;
  }