Ejemplo n.º 1
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;
  }
Ejemplo n.º 2
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;
  }
Ejemplo n.º 3
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;
  }