Пример #1
0
  /** @see org.overlord.sramp.shell.api.shell.ShellCommand#execute() */
  @Override
  public boolean execute() throws Exception {
    String filePathArg =
        this.requiredArgument(
            0, Messages.i18n.format("Upload.InvalidArgMsg.LocalFile")); // $NON-NLS-1$
    String artifactTypeArg = this.optionalArgument(1);

    QName clientVarName = new QName("s-ramp", "client"); // $NON-NLS-1$ //$NON-NLS-2$
    SrampAtomApiClient client = (SrampAtomApiClient) getContext().getVariable(clientVarName);
    if (client == null) {
      print(Messages.i18n.format("MissingSRAMPConnection")); // $NON-NLS-1$
      return false;
    }
    InputStream content = null;
    ZipToSrampArchive expander = null;
    SrampArchive archive = null;
    try {
      File file = new File(filePathArg);
      ArtifactType artifactType = null;
      if (artifactTypeArg != null) {
        artifactType = ArtifactType.valueOf(artifactTypeArg);
        if (artifactType.isExtendedType()) {
          artifactType = ArtifactType.ExtendedDocument(artifactType.getExtendedType());
        }
      } else {
        artifactType = determineArtifactType(file);
      }
      content = FileUtils.openInputStream(file);
      BaseArtifactType artifact = client.uploadArtifact(artifactType, content, file.getName());
      IOUtils.closeQuietly(content);

      // Now also add "expanded" content to the s-ramp repository
      expander = ZipToSrampArchiveRegistry.createExpander(artifactType, file);
      if (expander != null) {
        expander.setContextParam(DefaultMetaDataFactory.PARENT_UUID, artifact.getUuid());
        archive = expander.createSrampArchive();
        client.uploadBatch(archive);
      }

      // Put the artifact in the session as the active artifact
      QName artifactVarName = new QName("s-ramp", "artifact"); // $NON-NLS-1$ //$NON-NLS-2$
      getContext().setVariable(artifactVarName, artifact);
      print(Messages.i18n.format("Upload.Success")); // $NON-NLS-1$
      PrintArtifactMetaDataVisitor visitor = new PrintArtifactMetaDataVisitor();
      ArtifactVisitorHelper.visitArtifact(visitor, artifact);
    } catch (Exception e) {
      print(Messages.i18n.format("Upload.Failure")); // $NON-NLS-1$
      print("\t" + e.getMessage()); // $NON-NLS-1$
      IOUtils.closeQuietly(content);
      return false;
    }
    return true;
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.jboss.arquillian.container.sramp.SrampService#deployArchive(java.
   * lang.String, java.lang.String, java.io.InputStream)
   */
  public BaseArtifactType deployArchive(
      String archiveId, String archiveName, String artifactTypeArg, InputStream content) {

    assert content != null;

    ZipToSrampArchive expander = null;
    SrampArchive archive = null;
    BaseArtifactType artifact = null;
    File tempResourceFile = null;
    try {
      // internal integrity check
      artifactCounter = client.query("/s-ramp").getTotalResults();

      // First, stash the content in a temp file - we may need it multiple
      // times.
      tempResourceFile = stashResourceContent(content);
      content = FileUtils.openInputStream(tempResourceFile);

      ArtifactType artifactType = ArtifactType.valueOf(artifactTypeArg);
      if (artifactType.isExtendedType()) {
        artifactType = ArtifactType.ExtendedDocument(artifactType.getExtendedType());
      }

      artifact = client.uploadArtifact(artifactType, content, archiveName);
      IOUtils.closeQuietly(content);

      // for all uploaded files add custom property
      SrampModelUtils.setCustomProperty(artifact, "arquillian-archive-id", archiveId);
      client.updateArtifactMetaData(artifact);

      content = FileUtils.openInputStream(tempResourceFile);

      // Now also add "expanded" content to the s-ramp repository
      expander = ZipToSrampArchiveRegistry.createExpander(artifactType, content);

      if (expander != null) {
        expander.setContextParam(DefaultMetaDataFactory.PARENT_UUID, artifact.getUuid());
        archive = expander.createSrampArchive();
        client.uploadBatch(archive);
      }
    } catch (Exception e) {
      log.error("Upload failure:", e);
      IOUtils.closeQuietly(content);
    } finally {
      SrampArchive.closeQuietly(archive);
      ZipToSrampArchive.closeQuietly(expander);
      FileUtils.deleteQuietly(tempResourceFile);
    }

    return artifact;
  }
Пример #3
0
  /**
   * Uploads a single deployment to S-RAMP.
   *
   * @param deploymentType
   * @param fileName
   * @param client
   * @param tempFile
   * @param responseParams
   * @param version
   * @throws Exception
   */
  private void uploadSingleDeployment(
      String deploymentType,
      String fileName,
      File tempFile,
      Map<String, String> responseParams,
      String version)
      throws Exception {
    ArtifactType at = ArtifactType.valueOf(deploymentType);
    if (at.isExtendedType()) {
      at = ArtifactType.ExtendedDocument(at.getExtendedType());
    }
    String uuid = null;
    // First, upload the deployment
    InputStream contentStream = null;
    try {
      contentStream = FileUtils.openInputStream(tempFile);
      BaseArtifactType artifact = at.newArtifactInstance();
      artifact.setName(fileName);
      artifact.setVersion(version);
      artifact = clientAccessor.getClient().uploadArtifact(artifact, contentStream);
      responseParams.put("model", at.getArtifactType().getModel()); // $NON-NLS-1$
      responseParams.put("type", at.getArtifactType().getType()); // $NON-NLS-1$
      responseParams.put("uuid", artifact.getUuid()); // $NON-NLS-1$
      uuid = artifact.getUuid();
    } finally {
      IOUtils.closeQuietly(contentStream);
    }

    // Try to expand the artifact (works if an expander is available for the given artifact type).
    ZipToSrampArchive j2sramp = null;
    SrampArchive archive = null;
    try {
      j2sramp = ZipToSrampArchiveRegistry.createExpander(at, tempFile);
      if (j2sramp != null) {
        j2sramp.setContextParam(DefaultMetaDataFactory.PARENT_UUID, uuid);
        archive = j2sramp.createSrampArchive();
        clientAccessor.getClient().uploadBatch(archive);
      }
    } finally {
      SrampArchive.closeQuietly(archive);
      ZipToSrampArchive.closeQuietly(j2sramp);
    }
  }
Пример #4
0
 /**
  * {@inheritDoc}
  *
  * @see
  *     org.overlord.sramp.atom.archive.expand.registry.ZipToSrampArchiveProvider#accept(org.overlord.sramp.common.ArtifactType)
  */
 @Override
 public boolean accept(final ArtifactType artifactType) {
   return (artifactType.isExtendedType()
       && Vdb.ARTIFACT_TYPE.equals(artifactType.getExtendedType()));
 }