Package org.jclouds.io

Examples of org.jclouds.io.Payload


      }
      connection.setRequestProperty(HOST, host);
      if (connection.getRequestProperty(USER_AGENT) == null) {
          connection.setRequestProperty(USER_AGENT, DEFAULT_USER_AGENT);
      }
      Payload payload = request.getPayload();
      if (payload != null) {
         MutableContentMetadata md = payload.getContentMetadata();
         for (Map.Entry<String,String> entry : contentMetadataCodec.toHeaders(md).entries()) {
            connection.setRequestProperty(entry.getKey(), entry.getValue());
         }
         if (chunked) {
            connection.setChunkedStreamingMode(8196);
View Full Code Here


   
    // Launch Hadoop "master" (NN and JT)
    // deal with user packages and autoshutdown with extra runurls
    String hadoopInstallRunUrl = clusterSpec.getConfiguration().getString(
        "whirr.hadoop-install-runurl", "apache/hadoop/install");
    Payload nnjtBootScript = newStringPayload(runUrls(clusterSpec.getRunUrlBase(),
      String.format("util/configure-hostnames -c %s", clusterSpec.getProvider()),
      "sun/java/install",
      String.format("%s nn,jt -c %s", hadoopInstallRunUrl,
          clusterSpec.getProvider())));

    LOG.info("Configuring template");
    TemplateBuilder masterTemplateBuilder = computeService.templateBuilder()
      .options(runScript(nnjtBootScript)
      .installPrivateKey(clusterSpec.getPrivateKey())
      .authorizePublicKey(clusterSpec.getPublicKey()));
   
    TemplateBuilderStrategy strategy = new HadoopTemplateBuilderStrategy();
    strategy.configureTemplateBuilder(clusterSpec, masterTemplateBuilder);
   
    Template masterTemplate = masterTemplateBuilder.build();
   
    InstanceTemplate instanceTemplate = clusterSpec.getInstanceTemplate(MASTER_ROLE);
    checkNotNull(instanceTemplate);
    checkArgument(instanceTemplate.getNumberOfInstances() == 1);
    Set<? extends NodeMetadata> nodes;
    try {
      LOG.info("Starting master node");
      nodes = computeService.runNodesWithTag(
          clusterSpec.getClusterName(), 1, masterTemplate);
      LOG.info("Master node started: {}", nodes);
    } catch (RunNodesException e) {
      // TODO: can we do better here (retry?)
      throw new IOException(e);
    }
    NodeMetadata node = Iterables.getOnlyElement(nodes);
    InetAddress namenodePublicAddress = InetAddress.getByName(Iterables.get(node.getPublicAddresses(),0));
    InetAddress jobtrackerPublicAddress = InetAddress.getByName(Iterables.get(node.getPublicAddresses(),0));
   
    LOG.info("Authorizing firewall");
    FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
        WEB_PORT);
    FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
        NAMENODE_WEB_UI_PORT);
    FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
        JOBTRACKER_WEB_UI_PORT);
    FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
        namenodePublicAddress.getHostAddress(), NAMENODE_PORT);
    FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
        namenodePublicAddress.getHostAddress(), JOBTRACKER_PORT);
    if (!namenodePublicAddress.equals(jobtrackerPublicAddress)) {
      FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
          jobtrackerPublicAddress.getHostAddress(), NAMENODE_PORT);
      FirewallSettings.authorizeIngress(computeServiceContext, node, clusterSpec,
          jobtrackerPublicAddress.getHostAddress(), JOBTRACKER_PORT);
    }

    // Launch slaves (DN and TT)
    Payload slaveBootScript = newStringPayload(runUrls(clusterSpec.getRunUrlBase(),
      String.format("util/configure-hostnames -c %s", clusterSpec.getProvider()),
      "sun/java/install",
      String.format("%s dn,tt -n %s -j %s -c %s",
          hadoopInstallRunUrl,
          namenodePublicAddress.getHostName(),
View Full Code Here

   }

   private static final byte[] NO_CONTENT = new byte[] {};

   private static Payload payload(long bytes, String contentType) {
      Payload payload = Payloads.newByteArrayPayload(NO_CONTENT);
      payload.getContentMetadata().setContentLength(bytes);
      payload.getContentMetadata().setContentType(contentType);
      return payload;
   }
View Full Code Here

   public InputStream input(InputStream instream) {
      return copy("<< ", checkNotNull(instream, "input"));
   }

   public void input(PayloadEnclosing request) {
      Payload oldContent = request.getPayload();
      Payload wiredPayload = newPayload(input(oldContent.getInput()));
      copyPayloadMetadata(oldContent, wiredPayload);
      request.setPayload(wiredPayload);
   }
View Full Code Here

      copyPayloadMetadata(oldContent, wiredPayload);
      request.setPayload(wiredPayload);
   }

   public void output(PayloadEnclosing request) {
      Payload oldContent = request.getPayload();
      Payload wiredPayload;
      try {
         wiredPayload = newPayload(output(oldContent.getRawContent()));
      } catch (UnsupportedOperationException e) {
         wiredPayload = newPayload(output(oldContent.getInput()));
      }
View Full Code Here

  }

  public byte[] downloadData(String sid, String cid, String idthrows StorageCloudException {
    Blob bl = storage.getBlob(bucketname, id);
    Payload b = bl.getPayload();
    InputStream in = b.getInput();
    byte[] array = null;
   
    try {
      array = getBytesFromInputStream(in);
    } catch (IOException e) {
View Full Code Here

  public byte[] downloadData(String sid, String cid, String id) throws StorageCloudException {
    SwiftObject object = null;
    if(swift.getApi().objectExists(bucketName, id)){
      object = swift.getApi().getObject(bucketName, id);

      Payload pay = object.getPayload();
      InputStream in = pay.getInput();
      byte[] array = null;

      try {
        array = getBytesFromInputStream(in);
      } catch (IOException e) {
View Full Code Here

    }

    @Override
    public Payload get(String path) {
      LOG.info(toString() + " >> get(" + path + ")");
      Payload returnVal = contents.get(path);
      LOG.info(toString() + " << md5[" + md5Hex(returnVal) + "]");
      return returnVal;
    }
View Full Code Here

  private Template buildTemplate(ClusterSpec clusterSpec,
      ComputeService computeService, StatementBuilder statementBuilder,
      TemplateBuilderStrategy strategy)
      throws MalformedURLException {
    LOG.info("Configuring template");
    Payload script = newStringPayload(statementBuilder.render(OsFamily.UNIX));
    LOG.debug("Running script:\n{}", script.getRawContent());
    TemplateBuilder templateBuilder = computeService.templateBuilder()
      .options(runScript(script)
      .installPrivateKey(clusterSpec.getPrivateKey())
      .authorizePublicKey(clusterSpec.getPublicKey()));
    strategy.configureTemplateBuilder(clusterSpec, templateBuilder);
View Full Code Here

      Credentials credentials = new Credentials(
          Iterables.get(cluster.getInstances(), 0).getLoginCredentials().identity,
          clusterSpec.readPrivateKey());
      try {
        LOG.info("Running configuration script");
        Payload script = newStringPayload(statementBuilder.render(OsFamily.UNIX));
        LOG.debug("Running script:\n{}", script.getRawContent());
        computeService.runScriptOnNodesMatching(
            toNodeMetadataPredicate(clusterSpec, cluster, entry.getKey().getRoles()),
            script,
            RunScriptOptions.Builder.overrideCredentialsWith(credentials));
        LOG.info("Configuration script run completed");
View Full Code Here

TOP

Related Classes of org.jclouds.io.Payload

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.