Пример #1
0
  /**
   * Deploy content to the remote server - this is one half of #createResource
   *
   * @param report Create resource report that tells us what to do
   * @return report that tells us what has been done.
   */
  protected CreateResourceReport deployContent(CreateResourceReport report) {
    ContentContext cctx = context.getContentContext();
    ResourcePackageDetails details = report.getPackageDetails();

    ContentServices contentServices = cctx.getContentServices();
    String resourceTypeName = report.getResourceType().getName();

    ASUploadConnection uploadConnection = new ASUploadConnection(host, port);
    OutputStream out = uploadConnection.getOutputStream(details.getFileName());
    contentServices.downloadPackageBitsForChildResource(
        cctx, resourceTypeName, details.getKey(), out);

    JsonNode uploadResult = uploadConnection.finishUpload();
    if (verbose) log.info(uploadResult);

    if (ASUploadConnection.isErrorReply(uploadResult)) {
      report.setStatus(CreateResourceStatus.FAILURE);
      report.setErrorMessage(ASUploadConnection.getFailureDescription(uploadResult));

      return report;
    }

    String fileName = details.getFileName();

    if (fileName.startsWith(
        "C:\\fakepath\\")) { // TODO this is a hack as the server adds the fake path somehow
      fileName = fileName.substring("C:\\fakepath\\".length());
    }

    String tmpName = fileName; // TODO figure out the tmp-name biz with the AS guys

    JsonNode resultNode = uploadResult.get("result");
    String hash = resultNode.get("BYTES_VALUE").getTextValue();

    return runDeploymentMagicOnServer(report, fileName, tmpName, hash);
  }
Пример #2
0
  private File writeNewAppBitsToTempFile(
      ContentServices contentServices, ResourcePackageDetails packageDetails) throws Exception {
    File tempDir = this.resourceContext.getTemporaryDirectory();
    File tempFile = new File(tempDir, this.deploymentFile.getName());

    OutputStream tempOutputStream = null;
    try {
      tempOutputStream = new BufferedOutputStream(new FileOutputStream(tempFile));
      long bytesWritten =
          contentServices.downloadPackageBits(
              this.resourceContext.getContentContext(),
              packageDetails.getKey(),
              tempOutputStream,
              true);
      log.debug(
          "Wrote "
              + bytesWritten
              + " bytes to '"
              + tempFile //$NON-NLS-1$ //$NON-NLS-2$
              + "'."); //$NON-NLS-1$
    } catch (IOException e) {
      log.error(
          "Error writing updated application bits to temporary location: " //$NON-NLS-1$
              + tempFile,
          e);
      throw e;
    } finally {
      if (tempOutputStream != null) {
        try {
          tempOutputStream.close();
        } catch (IOException e) {
          log.error("Error closing temporary output stream", e); // $NON-NLS-1$
        }
      }
    }
    if (!tempFile.exists()) {
      log.error(
          "Temporary file for application update not written to: " //$NON-NLS-1$
              + tempFile);
      throw new Exception();
    }
    return tempFile;
  }