Search in sources :

Example 1 with WebResult

use of org.apache.hop.www.WebResult in project hop by apache.

the class RemoteWorkflowEngine method sendToHopServer.

/**
 * Send to hop server.
 *
 * @param workflowMeta the workflow meta
 * @param executionConfiguration the execution configuration
 * @param metadataProvider the metadataProvider
 * @throws HopException the hop exception
 */
public void sendToHopServer(IVariables variables, WorkflowMeta workflowMeta, WorkflowExecutionConfiguration executionConfiguration, IHopMetadataProvider metadataProvider) throws HopException {
    if (hopServer == null) {
        throw new HopException(BaseMessages.getString(PKG, "Workflow.Log.NoHopServerSpecified"));
    }
    if (Utils.isEmpty(workflowMeta.getName())) {
        throw new HopException(BaseMessages.getString(PKG, "Workflow.Log.UniqueWorkflowName"));
    }
    // Align logging levels between execution configuration and remote server
    hopServer.getLogChannel().setLogLevel(executionConfiguration.getLogLevel());
    try {
        // 
        for (String var : getVariableNames()) {
            if (RemotePipelineEngine.isVariablePassedToRemoteServer(var)) {
                executionConfiguration.getVariablesMap().put(var, getVariable(var));
            }
        }
        if (remoteWorkflowRunConfiguration.isExportingResources()) {
            // First export the workflow...
            // 
            FileObject tempFile = HopVfs.createTempFile("workflowExport", ".zip", System.getProperty("java.io.tmpdir"));
            TopLevelResource topLevelResource = ResourceUtil.serializeResourceExportInterface(tempFile.getName().toString(), workflowMeta, this, metadataProvider, executionConfiguration, CONFIGURATION_IN_EXPORT_FILENAME, remoteWorkflowRunConfiguration.getNamedResourcesSourceFolder(), remoteWorkflowRunConfiguration.getNamedResourcesTargetFolder(), executionConfiguration.getVariablesMap());
            // Send the zip file over to the hop server...
            String result = hopServer.sendExport(this, topLevelResource.getArchiveName(), RegisterPackageServlet.TYPE_WORKFLOW, topLevelResource.getBaseResourceName());
            WebResult webResult = WebResult.fromXmlString(result);
            if (!webResult.getResult().equalsIgnoreCase(WebResult.STRING_OK)) {
                throw new HopException("There was an error passing the exported workflow to the remote server: " + Const.CR + webResult.getMessage());
            }
            containerId = webResult.getId();
        } else {
            String xml = new WorkflowConfiguration(workflowMeta, executionConfiguration, metadataProvider).getXml(variables);
            String reply = hopServer.sendXml(this, xml, RegisterWorkflowServlet.CONTEXT_PATH + "/?xml=Y");
            WebResult webResult = WebResult.fromXmlString(reply);
            if (!webResult.getResult().equalsIgnoreCase(WebResult.STRING_OK)) {
                throw new HopException("There was an error posting the workflow on the remote server: " + Const.CR + webResult.getMessage());
            }
            containerId = webResult.getId();
        }
        // Start the workflow
        // 
        WebResult webResult = hopServer.startWorkflow(this, workflowMeta.getName(), containerId);
        if (!webResult.getResult().equalsIgnoreCase(WebResult.STRING_OK)) {
            throw new HopException("There was an error starting the workflow on the remote server: " + Const.CR + webResult.getMessage().replace('\t', '\n'));
        }
    } catch (HopException ke) {
        throw ke;
    } catch (Exception e) {
        throw new HopException(e);
    }
}
Also used : TopLevelResource(org.apache.hop.resource.TopLevelResource) HopException(org.apache.hop.core.exception.HopException) FileObject(org.apache.commons.vfs2.FileObject) WebResult(org.apache.hop.www.WebResult) HopException(org.apache.hop.core.exception.HopException)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)1 HopException (org.apache.hop.core.exception.HopException)1 TopLevelResource (org.apache.hop.resource.TopLevelResource)1 WebResult (org.apache.hop.www.WebResult)1