Package org.apache.airavata.core.gfac.exception

Examples of org.apache.airavata.core.gfac.exception.ProviderException


            if (hostgridFTP == null || hostgridFTP.length == 0) {
                hostgridFTP = new String[] { host.getHostAddress() };
            }

            boolean success = false;
            ProviderException pe = null;// = new ProviderException("");

            for (String endpoint : host.getGridFTPEndPointArray()) {
                try {

                    URI tmpdirURI = GfacUtils.createGsiftpURI(endpoint, app.getScratchWorkingDirectory());
                    URI workingDirURI = GfacUtils.createGsiftpURI(endpoint, app.getStaticWorkingDirectory());
                    URI inputURI = GfacUtils.createGsiftpURI(endpoint, app.getInputDataDirectory());
                    URI outputURI = GfacUtils.createGsiftpURI(endpoint, app.getOutputDataDirectory());

                    log.debug("Host FTP = " + hostgridFTP);
                    log.debug("temp directory = " + tmpdirURI);
                    log.debug("Working directory = " + workingDirURI);
                    log.debug("Input directory = " + inputURI);
                    log.debug("Output directory = " + outputURI);

                    ftp.makeDir(tmpdirURI, gssCred);
                    ftp.makeDir(workingDirURI, gssCred);
                    ftp.makeDir(inputURI, gssCred);
                    ftp.makeDir(outputURI, gssCred);

                    success = true;
                    break;
                } catch (URISyntaxException e) {
                    pe = new ProviderException("URI is malformatted:" + e.getMessage(), e,invocationContext);

                } catch (ToolsException e) {
                    pe = new ProviderException(e.getMessage(), e,invocationContext);
                }
            }
            if (success == false) {
                throw pe;
            }
        } catch (SecurityException e) {
            throw new ProviderException(e.getMessage(), e,invocationContext);
        }
    }
View Full Code Here


            job = new GramJob(rsl);
            listener = new JobSubmissionListener(job, invocationContext);
            job.addListener(listener);

        } catch (ToolsException te) {
            throw new ProviderException(te.getMessage(), te, invocationContext);
        }

    }
View Full Code Here

            JobSubmissionFault error = new JobSubmissionFault(this, e, host.getHostAddress(), gateKeeper, job.getRSL(), invocationContext);
            int errCode = listener.getError();
            error.sendFaultNotification(error.getMessage(),invocationContext,error,host.getHostAddress()+ "," + job.getRSL());
        throw errorReason(errCode, error);
        } catch (GSSException e) {
            throw new ProviderException(e.getMessage(), e, invocationContext);
        } catch (InterruptedException e) {
            throw new ProviderException("Thread", e,invocationContext);
        } catch (SecurityException e) {
            throw new ProviderException(e.getMessage(), e,invocationContext);
        } finally {
            if (job != null) {
                try {
                    job.cancel();
                } catch (Exception e) {
View Full Code Here

            String[] hostgridFTP = host.getGridFTPEndPointArray();
            if (hostgridFTP == null || hostgridFTP.length == 0) {
                hostgridFTP = new String[] { host.getHostAddress() };
            }
            ProviderException pe = null;
            for (String endpoint : host.getGridFTPEndPointArray()) {
                try {
                    /*
                     *  Read Stdout and Stderror
                     */
                    URI stdoutURI = GfacUtils.createGsiftpURI(endpoint, app.getStandardOutput());
                    URI stderrURI = GfacUtils.createGsiftpURI(endpoint, app.getStandardError());

                    log.info("STDOUT:" + stdoutURI.toString());
                    log.info("STDERR:" + stderrURI.toString());

                    File logDir = new File("./service_logs");
                    if (!logDir.exists()) {
                        logDir.mkdir();
                    }

                    String timeStampedServiceName = GfacUtils.createUniqueNameForService(invocationContext
                            .getServiceName());
                    File localStdOutFile = File.createTempFile(timeStampedServiceName, "stdout");
                    localStdErrFile = File.createTempFile(timeStampedServiceName, "stderr");

                    String stdout = ftp.readRemoteFile(stdoutURI, gssCred, localStdOutFile);
                    String stderr = ftp.readRemoteFile(stderrURI, gssCred, localStdErrFile);
                    Map<String,ActualParameter> stringMap = null;
                    MessageContext<Object> output = invocationContext.getOutput();
                    for (Iterator<String> iterator = output.getNames(); iterator.hasNext(); ) {
                        String paramName = iterator.next();
                        ActualParameter actualParameter = (ActualParameter) output.getValue(paramName);
            if ("URIArray".equals(actualParameter.getType().getType().toString())) {
              URI outputURI = GfacUtils.createGsiftpURI(endpoint,app.getOutputDataDirectory());
              List<String> outputList = ftp.listDir(outputURI,gssCred);
              String[] valueList = outputList.toArray(new String[outputList.size()]);
              ((URIArrayType) actualParameter.getType()).setValueArray(valueList);
              stringMap = new HashMap<String, ActualParameter>();
              stringMap.put(paramName, actualParameter);
              invocationContext.getExecutionContext().getNotifier().output(invocationContext, actualParameter.toString());
            }
                        if ("StringArray".equals(actualParameter.getType().getType().toString())) {
                            String[] valueList = OutputUtils.parseStdoutArray(stdout, paramName);
                            ((StringArrayType) actualParameter.getType()).setValueArray(valueList);
                            stringMap = new HashMap<String, ActualParameter>();
                            stringMap.put(paramName, actualParameter);
                            invocationContext.getExecutionContext().getNotifier().output(invocationContext, actualParameter.toString());
                        }
                      else{
                      // This is to handle exception during the output parsing.
                        stringMap = OutputUtils.fillOutputFromStdout(invocationContext.<ActualParameter>getOutput(), stdout,stderr);
                        String paramValue = output.getStringValue(paramName);
                        if(paramValue == null || paramValue.isEmpty()){
                            int errCode = listener.getError();
                            String errorMsg = "Job " + job.getID() + " on host " + host.getHostAddress();
                            JobSubmissionFault error = new JobSubmissionFault(this, new Exception(errorMsg), "GFAC HOST",
                                    gateKeeper, job.getRSL(), invocationContext);
                            errorReason(errCode, error);
                            invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext,error,
                                    readLastLinesofStdOut(localStdErrFile.getPath(), 20));
                            throw error;
                        }
                        }
                    }
                    if(stringMap == null || stringMap.isEmpty()){
                      ProviderException exception = new ProviderException("Gram provider: Error creating job output", invocationContext);
                       invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext,exception,exception.getLocalizedMessage());
                         throw exception;
                    }
                    // If users has given an output DAta poth we download the output files in to that directory, this will be apath in the machine where GFac is installed
                    if(WorkflowContextHeaderBuilder.getCurrentContextHeader() != null &&
                            WorkflowContextHeaderBuilder.getCurrentContextHeader().getWorkflowOutputDataHandling() != null){
                        WorkflowOutputDataHandlingDocument.WorkflowOutputDataHandling workflowOutputDataHandling =
                                WorkflowContextHeaderBuilder.getCurrentContextHeader().getWorkflowOutputDataHandling();
                        if(workflowOutputDataHandling.getApplicationOutputDataHandlingArray().length != 0){
                            String outputDataDirectory = workflowOutputDataHandling.getApplicationOutputDataHandlingArray()[0].getOutputDataDirectory();
                            if(outputDataDirectory != null && !"".equals(outputDataDirectory)){
                                stageOutputFiles(invocationContext,outputDataDirectory);
                            }
                        }
                    }
                    return stringMap;
                }catch (XmlException e) {
                    throw new ProviderException(e.getMessage(), e,invocationContext,readLastLinesofStdOut(localStdErrFile.getPath(), 20));
                }
                catch (ToolsException e) {
                    throw new ProviderException(e.getMessage(), e,invocationContext,readLastLinesofStdOut(localStdErrFile.getPath(), 20));
                } catch (URISyntaxException e) {
                    throw new ProviderException("URI is malformatted:" + e.getMessage(), e, invocationContext,readLastLinesofStdOut(localStdErrFile.getPath(), 20));
                }catch (NullPointerException e) {
                    throw new ProviderException("Output is not produced in stdout:" + e.getMessage(), e, invocationContext, readLastLinesofStdOut(localStdErrFile.getPath(), 20));
                }
            }

            /*
             * If the execution reach here, all GridFTP Endpoint is failed.
             */
            throw pe;

        } catch (Exception e) {
//            invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext,e,readLastLinesofStdOut(localStdErrFile.getPath(), 20));
            throw new ProviderException(e.getMessage(), e, invocationContext, readLastLinesofStdOut(localStdErrFile.getPath(), 20));
        }

    }
View Full Code Here

            }
      inputNew.add(paramName, actualParameter);
    }
        }catch (Exception e){
//           invocationContext.getExecutionContext().getNotifier().executionFail(invocationContext,e,"Error during Input File staging");
            throw new ProviderException("Error while input File Staging", e.getCause(),invocationContext,  e.getLocalizedMessage());
        }
        invocationContext.setInput(inputNew);
    return null;
  }
View Full Code Here

                        ((URIArrayType) actualParameter.getType()).setValueArray(newFiles.toArray(new String[newFiles.size()]));
                    }

                }
            } catch (URISyntaxException e) {
                throw new ProviderException(e.getMessage(), e, invocationContext);
            } catch (ToolsException e) {
                throw new ProviderException(e.getMessage(), e, invocationContext);
            }
            outputNew.add(paramName, actualParameter);
        }
        invocationContext.setOutput(outputNew);
    }
View Full Code Here

        /*
         * Validation
         */
        if (access_key == null || access_key.isEmpty())
            throw new ProviderException("EC2 Access Key is empty", invocationContext);
        if (secret_key == null || secret_key.isEmpty())
            throw new ProviderException("EC2 Secret Key is empty", invocationContext);
        if ((ami_id == null && ins_id == null) || (ami_id != null && ami_id.isEmpty()) || (ins_id != null && ins_id.isEmpty()))
            throw new ProviderException("EC2 AMI or Instance ID is empty", invocationContext);
        if (this.username == null || this.username.isEmpty())
            throw new ProviderException("EC2 Username is empty", invocationContext);

        /*
         * Need to start EC2 instance before running it
         */
        AWSCredentials credential = new BasicAWSCredentials(access_key, secret_key);
        AmazonEC2Client ec2client = new AmazonEC2Client(credential);

        try {
            /*
             * Build key pair before start instance
             */
            buildKeyPair(ec2client);

            // right now, we can run it on one host
            if (ami_id != null)
                this.instance = startInstances(ec2client, ami_id, ins_type, execContext).get(0);
            else {

                // already running instance
                DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
                DescribeInstancesResult describeInstancesResult = ec2client.describeInstances(describeInstancesRequest.withInstanceIds(ins_id));

                if (describeInstancesResult.getReservations().size() == 0 || describeInstancesResult.getReservations().get(0).getInstances().size() == 0) {
                    throw new GfacException("Instance not found:" + ins_id);
                }

                this.instance = describeInstancesResult.getReservations().get(0).getInstances().get(0);

                // check instance keypair
                if (this.instance.getKeyName() == null || !this.instance.getKeyName().equals(KEY_PAIR_NAME))
                    throw new GfacException("Keypair for instance:" + ins_id + " is not valid");
            }

            //TODO send out instance id
            //execContext.getNotificationService().sendResourceMappingNotifications(this.instance.getPublicDnsName(), "EC2 Instance " + this.instance.getInstanceId() + " is running with public name " + this.instance.getPublicDnsName(), this.instance.getInstanceId());


            /*
             * Make sure port 22 is connectable
             */
            for (GroupIdentifier g : this.instance.getSecurityGroups()) {
                IpPermission ip = new IpPermission();
                ip.setIpProtocol("tcp");
                ip.setFromPort(22);
                ip.setToPort(22);
                AuthorizeSecurityGroupIngressRequest r = new AuthorizeSecurityGroupIngressRequest();
                r = r.withIpPermissions(ip.withIpRanges("0.0.0.0/0"));
                r.setGroupId(g.getGroupId());
                try {
                    ec2client.authorizeSecurityGroupIngress(r);
                } catch (AmazonServiceException as) {
                    /*
                     * If exception is from duplicate room, ignore it.
                     */
                    if (!as.getErrorCode().equals("InvalidPermission.Duplicate"))
                        throw as;
                }
            }

        } catch (Exception e) {
            throw new ProviderException("Invalied Request",e,invocationContext);
        }

        SSHSecurityContextImpl sshContext = ((SSHSecurityContextImpl) invocationContext.getSecurityContext(SSH_SECURITY_CONTEXT));
        if (sshContext == null) {
            sshContext = new SSHSecurityContextImpl();
View Full Code Here

    private void makeFileSystemDir(String dir, InvocationContext invocationContext) throws ProviderException {
        File f = new File(dir);
        if (f.isDirectory() && f.exists()) {
            return;
        } else if (!new File(dir).mkdir()) {
            throw new ProviderException("Cannot make directory "+dir, invocationContext);
        }
    }
View Full Code Here

                    .append(String.valueOf(returnValue));

            log.debug(buf.toString());

        } catch (IOException io) {
            throw new ProviderException(io.getMessage(), io,context);
        } catch (InterruptedException e) {
            throw new ProviderException(e.getMessage(), e, context);
        }
    }
View Full Code Here

            String stdErrStr = GfacUtils.readFileToString(app.getStandardError());

            // set to context
            return OutputUtils.fillOutputFromStdout(context.<ActualParameter>getOutput(), stdOutStr, stdErrStr);
        } catch (XmlException e) {
            throw new ProviderException("Cannot read output:" + e.getMessage(), e, context);
        } catch (IOException io) {
            throw new ProviderException(io.getMessage(), io, context);
        } catch (Exception e){
          throw new ProviderException("Error in retrieving results",e,context);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.airavata.core.gfac.exception.ProviderException

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.