Search in sources :

Example 1 with EngineUnavailableException

use of it.eng.spagobi.engines.talend.client.exception.EngineUnavailableException in project tdi-studio-se by Talend.

the class SpagoBITalendEngineClient_0_5_0 method deployJob.

/*
     * (non-Javadoc)
     * 
     * @see
     * it.eng.spagobi.engines.talend.client.ISpagoBITalendEngineClient#deployJob(it.eng.spagobi.engines.talend.client
     * .JobDeploymentDescriptor, java.io.File)
     */
public boolean deployJob(JobDeploymentDescriptor jobDeploymentDescriptor, File executableJobFiles) throws EngineUnavailableException, AuthenticationFailedException, ServiceInvocationFailedException {
    HttpClient client;
    PostMethod method;
    File deploymentDescriptorFile;
    boolean result = false;
    client = new HttpClient();
    method = new PostMethod(getServiceUrl(JOB_UPLOAD_SERVICE));
    deploymentDescriptorFile = null;
    try {
        //$NON-NLS-1$ //$NON-NLS-2$
        deploymentDescriptorFile = File.createTempFile("deploymentDescriptor", ".xml");
        FileWriter writer = new FileWriter(deploymentDescriptorFile);
        writer.write(jobDeploymentDescriptor.toXml());
        writer.flush();
        writer.close();
        Part[] parts = { new FilePart(executableJobFiles.getName(), executableJobFiles), //$NON-NLS-1$
        new FilePart("deploymentDescriptor", deploymentDescriptorFile) };
        method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams()));
        client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
        int status = client.executeMethod(method);
        if (status == HttpStatus.SC_OK) {
            if (//$NON-NLS-1$
            method.getResponseBodyAsString().equalsIgnoreCase("OK"))
                result = true;
        } else {
            throw new ServiceInvocationFailedException(Messages.getString("SpagoBITalendEngineClient_0_5_0.serviceExcFailed") + JOB_UPLOAD_SERVICE, //$NON-NLS-1$
            method.getStatusLine().toString(), method.getResponseBodyAsString());
        }
    } catch (HttpException e) {
        //$NON-NLS-1$
        throw new EngineUnavailableException(Messages.getString("SpagoBITalendEngineClient_0_5_0.protocolViolation") + e.getMessage());
    } catch (IOException e) {
        //$NON-NLS-1$
        throw new EngineUnavailableException(Messages.getString("SpagoBITalendEngineClient_0_5_0.transportError") + e.getMessage());
    } finally {
        method.releaseConnection();
        if (deploymentDescriptorFile != null)
            deploymentDescriptorFile.delete();
    }
    return result;
}
Also used : ServiceInvocationFailedException(it.eng.spagobi.engines.talend.client.exception.ServiceInvocationFailedException) PostMethod(org.apache.commons.httpclient.methods.PostMethod) FileWriter(java.io.FileWriter) IOException(java.io.IOException) MultipartRequestEntity(org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity) FilePart(org.apache.commons.httpclient.methods.multipart.FilePart) EngineUnavailableException(it.eng.spagobi.engines.talend.client.exception.EngineUnavailableException) FilePart(org.apache.commons.httpclient.methods.multipart.FilePart) Part(org.apache.commons.httpclient.methods.multipart.Part) HttpClient(org.apache.commons.httpclient.HttpClient) HttpException(org.apache.commons.httpclient.HttpException) File(java.io.File)

Example 2 with EngineUnavailableException

use of it.eng.spagobi.engines.talend.client.exception.EngineUnavailableException in project tdi-studio-se by Talend.

the class SpagoBITalendEngineClientDemo method main.

public static void main(String[] args) throws ZipException, IOException {
    if (args.length < 6) {
        usage();
        System.exit(1);
    }
    String user = args[0];
    String password = args[1];
    String host = args[2];
    String port = args[3];
    String applicationContext = args[4];
    String deploymentFile = args[5];
    try {
        // create the client
        ISpagoBITalendEngineClient client = new SpagoBITalendEngineClient(user, password, host, port, applicationContext);
        // get some informations about the engine instance referenced by the client
        //$NON-NLS-1$
        System.out.println("Engine version: " + client.getEngineVersion());
        //$NON-NLS-1$
        System.out.println("Engine fullname: " + client.getEngineName());
        // prepare parameters used during deployment
        //$NON-NLS-1$ //$NON-NLS-2$
        JobDeploymentDescriptor jobDeploymentDescriptor = new JobDeploymentDescriptor("Test", "perl");
        File zipFile = new File(deploymentFile);
        // deploy job on engine runtime
        boolean result = client.deployJob(jobDeploymentDescriptor, zipFile);
        if (result)
            //$NON-NLS-1$
            System.out.println("Jobs deployed succesfully");
        else
            //$NON-NLS-1$
            System.out.println("Jobs not deployed");
    } catch (EngineUnavailableException e) {
        //$NON-NLS-1$
        System.err.println("ERRORE: " + e.getMessage());
    } catch (AuthenticationFailedException e) {
        //$NON-NLS-1$
        System.err.println("ERRORE: " + e.getMessage());
    } catch (UnsupportedEngineVersionException e) {
        //$NON-NLS-1$
        System.err.println("ERROR: Unsupported engine version");
        System.err.println(//$NON-NLS-1$
        "You are using TalendEngineClientAPI version " + SpagoBITalendEngineClient.CLIENTAPI_VERSION_NUMBER + //$NON-NLS-1$
        ". " + //$NON-NLS-1$
        "The TalendEngine instance you are trying to connect to require TalendEngineClientAPI version " + e.getComplianceVersion() + //$NON-NLS-1$
        " or grater.");
    } catch (ServiceInvocationFailedException e) {
        //$NON-NLS-1$
        System.err.println("ERRORE: " + e.getMessage());
        //$NON-NLS-1$ //$NON-NLS-2$
        System.err.println("StatusLine: " + e.getStatusLine() + "responseBody: " + e.getResponseBody());
    }
}
Also used : ServiceInvocationFailedException(it.eng.spagobi.engines.talend.client.exception.ServiceInvocationFailedException) JobDeploymentDescriptor(it.eng.spagobi.engines.talend.client.JobDeploymentDescriptor) EngineUnavailableException(it.eng.spagobi.engines.talend.client.exception.EngineUnavailableException) UnsupportedEngineVersionException(it.eng.spagobi.engines.talend.client.exception.UnsupportedEngineVersionException) AuthenticationFailedException(it.eng.spagobi.engines.talend.client.exception.AuthenticationFailedException) SpagoBITalendEngineClient(it.eng.spagobi.engines.talend.client.SpagoBITalendEngineClient) ISpagoBITalendEngineClient(it.eng.spagobi.engines.talend.client.ISpagoBITalendEngineClient) ISpagoBITalendEngineClient(it.eng.spagobi.engines.talend.client.ISpagoBITalendEngineClient) File(java.io.File)

Example 3 with EngineUnavailableException

use of it.eng.spagobi.engines.talend.client.exception.EngineUnavailableException in project tdi-studio-se by Talend.

the class PublishOnSpagoExportWizardPage method finish.

/**
     * The Finish button was pressed. Try to do the required work now and answer a boolean indicating success. If false
     * is returned then the wizard will not close.
     * 
     * @returns boolean
     */
public boolean finish() {
    Map<ExportChoice, Object> exportChoiceMap = getExportChoiceMap();
    boolean canExport = false;
    for (ExportChoice choice : ExportChoice.values()) {
        if (exportChoiceMap.get(choice) != null && exportChoiceMap.get(choice) instanceof Boolean && (Boolean) exportChoiceMap.get(choice)) {
            canExport = true;
            break;
        }
    }
    if (!canExport) {
        MessageDialog.openInformation(getContainer().getShell(), //$NON-NLS-1$
        Messages.getString("PublishOnSpagoExportWizardPage.publishResourceError"), //$NON-NLS-1$
        Messages.getString("PublishOnSpagoExportWizardPage.chooseResource"));
        return false;
    }
    if (!ensureTargetIsValid()) {
        return false;
    }
    String topFolder = getRootFolderName();
    manager = new //$NON-NLS-1$
    JobJavaScriptsManager(//$NON-NLS-1$
    exportChoiceMap, //$NON-NLS-1$
    contextCombo.getText(), //$NON-NLS-1$
    "all", //$NON-NLS-1$
    IProcessor.NO_STATISTICS, IProcessor.NO_TRACES);
    List<ExportFileResource> resourcesToExport = null;
    try {
        resourcesToExport = getExportResources();
    } catch (ProcessorException e) {
        MessageBoxExceptionHandler.process(e);
        return false;
    }
    setTopFolder(resourcesToExport, topFolder);
    // Save dirty editors if possible but do not stop if not all are saved
    saveDirtyEditors();
    // about to invoke the operation so save our state
    saveWidgetValues();
    // boolean ok = executeExportOperation(new ArchiveFileExportOperationFullPath(process));
    ArchiveFileExportOperationFullPath exporterOperation = getExporterOperation(resourcesToExport);
    boolean ok = executeExportOperation(exporterOperation);
    // path can like name/name
    manager.deleteTempFiles();
    ProcessorUtilities.resetExportConfig();
    for (int i = 0; i < process.length; i++) {
        ProcessItem processItem = (ProcessItem) process[i].getItem();
        try {
            ProcessorUtilities.generateCode(processItem, processItem.getProcess().getDefaultContext(), false, false);
        } catch (ProcessorException e) {
            ExceptionHandler.process(e);
        }
    }
    // cantoine : connection to SpagoBiEngineClient to publish Job.
    try {
        Project project = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject();
        // retrieve user, password, host, port from selected SpagoBiServer
        String selectedSpagoBiEngineName = serverSpagoBi.getItem(serverSpagoBi.getSelectionIndex());
        SpagoBiServer spagoBiServer = null;
        List<SpagoBiServer> listServerSapgo = null;
        // ProxyRepositoryFactory proxyRepositoryFactory = ProxyRepositoryFactory.getInstance();
        // try {
        listServerSapgo = SpagoBiServerHelper.parse(new SpagoBiPreferencePage().getPreferenceStore().getString(SpagoBiServer.SPAGOBI_SERVER));
        if (listServerSapgo != null && !listServerSapgo.isEmpty()) {
            Iterator<SpagoBiServer> iterator = listServerSapgo.iterator();
            while (iterator.hasNext()) {
                spagoBiServer = iterator.next();
                if (spagoBiServer.getEngineName().equals(selectedSpagoBiEngineName)) {
                    break;
                }
            }
        }
        // } catch (PersistenceException e) {
        // displayErrorDialog(e.getMessage());
        // }
        // "biadmin";
        String user = spagoBiServer.getLogin();
        // "biadmin";
        String password = spagoBiServer.getPassword();
        String host = spagoBiServer.getHost();
        String port = spagoBiServer.getPort();
        // create the client
        //$NON-NLS-1$
        ISpagoBITalendEngineClient client = new SpagoBITalendEngineClient(user, password, host, port, "SpagoBITalendEngine");
        // get some informations about the engine instance referenced by the client
        //$NON-NLS-1$
        System.out.println("Engine version: " + client.getEngineVersion());
        //$NON-NLS-1$
        System.out.println("Engine fullname: " + client.getEngineName());
        // prepare parameters used during deployment
        JobDeploymentDescriptor jobDeploymentDescriptor = new JobDeploymentDescriptor(project.getLabel(), project.getLanguage().getName());
        File zipFile = new File(getDestinationValue());
        // deploy job on engine runtime
        boolean result = client.deployJob(jobDeploymentDescriptor, zipFile);
        if (result)
            //$NON-NLS-1$
            System.out.println("Jobs deployed succesfully");
        else
            //$NON-NLS-1$
            System.out.println("Jobs not deployed");
    } catch (EngineUnavailableException e) {
        //$NON-NLS-1$
        System.err.println("ERROR: " + e.getMessage());
    } catch (AuthenticationFailedException e) {
        //$NON-NLS-1$
        System.err.println("ERROR: " + e.getMessage());
    } catch (UnsupportedEngineVersionException e) {
        //$NON-NLS-1$
        System.err.println("ERROR: Unsupported engine version");
        System.err.println(//$NON-NLS-1$
        "You are using TalendEngineClientAPI version " + SpagoBITalendEngineClient.CLIENTAPI_VERSION_NUMBER + //$NON-NLS-1$
        ". " + //$NON-NLS-1$
        "The TalendEngine instance you are trying to connect to require TalendEngineClientAPI version " + e.getComplianceVersion() + //$NON-NLS-1$
        " or grater.");
    } catch (ServiceInvocationFailedException e) {
        //$NON-NLS-1$
        System.err.println("ERROR: " + e.getMessage());
        //$NON-NLS-1$ //$NON-NLS-2$
        System.err.println("StatusLine: " + e.getStatusLine() + "responseBody: " + e.getResponseBody());
    }
    return ok;
// return true;
}
Also used : SpagoBiServer(org.talend.core.model.properties.SpagoBiServer) ServiceInvocationFailedException(it.eng.spagobi.engines.talend.client.exception.ServiceInvocationFailedException) RepositoryContext(org.talend.core.context.RepositoryContext) JobDeploymentDescriptor(it.eng.spagobi.engines.talend.client.JobDeploymentDescriptor) AuthenticationFailedException(it.eng.spagobi.engines.talend.client.exception.AuthenticationFailedException) ISpagoBITalendEngineClient(it.eng.spagobi.engines.talend.client.ISpagoBITalendEngineClient) SpagoBITalendEngineClient(it.eng.spagobi.engines.talend.client.SpagoBITalendEngineClient) SpagoBiPreferencePage(org.talend.sbi.engines.client.ui.preferences.SpagoBiPreferencePage) ProcessorException(org.talend.designer.runprocess.ProcessorException) UnsupportedEngineVersionException(it.eng.spagobi.engines.talend.client.exception.UnsupportedEngineVersionException) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) Project(org.talend.core.model.general.Project) EngineUnavailableException(it.eng.spagobi.engines.talend.client.exception.EngineUnavailableException) ProcessItem(org.talend.core.model.properties.ProcessItem) ExportFileResource(org.talend.repository.documentation.ExportFileResource) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ISpagoBITalendEngineClient(it.eng.spagobi.engines.talend.client.ISpagoBITalendEngineClient) File(java.io.File) ArchiveFileExportOperationFullPath(org.talend.core.ui.export.ArchiveFileExportOperationFullPath)

Example 4 with EngineUnavailableException

use of it.eng.spagobi.engines.talend.client.exception.EngineUnavailableException in project tdi-studio-se by Talend.

the class SpagoBITalendEngineClient method getEngineComplianceVersion.

public static String getEngineComplianceVersion(String url) throws EngineUnavailableException, ServiceInvocationFailedException {
    String version;
    HttpClient client;
    PostMethod method;
    NameValuePair[] nameValuePairs;
    version = null;
    client = new HttpClient();
    method = new PostMethod(url);
    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
    //$NON-NLS-1$ //$NON-NLS-2$
    nameValuePairs = new NameValuePair[] { new NameValuePair("infoType", "complianceVersion") };
    method.setRequestBody(nameValuePairs);
    try {
        // Execute the method.
        int statusCode = client.executeMethod(method);
        if (statusCode != HttpStatus.SC_OK) {
            throw new ServiceInvocationFailedException(Messages.getString("SpagoBITalendEngineClient.serviceFailed"), method.getStatusLine().toString(), //$NON-NLS-1$
            method.getResponseBodyAsString());
        } else {
            version = method.getResponseBodyAsString();
        }
    } catch (HttpException e) {
        //$NON-NLS-1$
        throw new EngineUnavailableException(Messages.getString("SpagoBITalendEngineClient.5", e.getMessage()));
    } catch (IOException e) {
        //$NON-NLS-1$
        throw new EngineUnavailableException(Messages.getString("SpagoBITalendEngineClient.6", e.getMessage()));
    } finally {
        // Release the connection.
        method.releaseConnection();
    }
    return version;
}
Also used : ServiceInvocationFailedException(it.eng.spagobi.engines.talend.client.exception.ServiceInvocationFailedException) NameValuePair(org.apache.commons.httpclient.NameValuePair) EngineUnavailableException(it.eng.spagobi.engines.talend.client.exception.EngineUnavailableException) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) DefaultHttpMethodRetryHandler(org.apache.commons.httpclient.DefaultHttpMethodRetryHandler) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException)

Example 5 with EngineUnavailableException

use of it.eng.spagobi.engines.talend.client.exception.EngineUnavailableException in project tdi-studio-se by Talend.

the class SpagoBITalendEngineClient_0_5_0 method getEngineInfo.

private String getEngineInfo(String infoType) throws EngineUnavailableException, ServiceInvocationFailedException {
    String version;
    HttpClient client;
    PostMethod method;
    NameValuePair[] nameValuePairs;
    version = null;
    client = new HttpClient();
    method = new PostMethod(getServiceUrl(ENGINE_INFO_SERVICE));
    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
    //$NON-NLS-1$
    nameValuePairs = new NameValuePair[] { new NameValuePair("infoType", infoType) };
    method.setRequestBody(nameValuePairs);
    try {
        // Execute the method.
        int statusCode = client.executeMethod(method);
        if (statusCode != HttpStatus.SC_OK) {
            throw new ServiceInvocationFailedException(Messages.getString("SpagoBITalendEngineClient_0_5_0.serviceExcFailed") + ENGINE_INFO_SERVICE, //$NON-NLS-1$
            method.getStatusLine().toString(), method.getResponseBodyAsString());
        } else {
            version = method.getResponseBodyAsString();
        }
    } catch (HttpException e) {
        //$NON-NLS-1$
        throw new EngineUnavailableException(Messages.getString("SpagoBITalendEngineClient_0_5_0.protocolViolation") + e.getMessage());
    } catch (IOException e) {
        //$NON-NLS-1$
        throw new EngineUnavailableException(Messages.getString("SpagoBITalendEngineClient_0_5_0.transportError") + e.getMessage());
    } finally {
        // Release the connection.
        method.releaseConnection();
    }
    return version;
}
Also used : ServiceInvocationFailedException(it.eng.spagobi.engines.talend.client.exception.ServiceInvocationFailedException) NameValuePair(org.apache.commons.httpclient.NameValuePair) EngineUnavailableException(it.eng.spagobi.engines.talend.client.exception.EngineUnavailableException) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) DefaultHttpMethodRetryHandler(org.apache.commons.httpclient.DefaultHttpMethodRetryHandler) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException)

Aggregations

EngineUnavailableException (it.eng.spagobi.engines.talend.client.exception.EngineUnavailableException)5 ServiceInvocationFailedException (it.eng.spagobi.engines.talend.client.exception.ServiceInvocationFailedException)5 File (java.io.File)3 IOException (java.io.IOException)3 HttpClient (org.apache.commons.httpclient.HttpClient)3 HttpException (org.apache.commons.httpclient.HttpException)3 PostMethod (org.apache.commons.httpclient.methods.PostMethod)3 ISpagoBITalendEngineClient (it.eng.spagobi.engines.talend.client.ISpagoBITalendEngineClient)2 JobDeploymentDescriptor (it.eng.spagobi.engines.talend.client.JobDeploymentDescriptor)2 SpagoBITalendEngineClient (it.eng.spagobi.engines.talend.client.SpagoBITalendEngineClient)2 AuthenticationFailedException (it.eng.spagobi.engines.talend.client.exception.AuthenticationFailedException)2 UnsupportedEngineVersionException (it.eng.spagobi.engines.talend.client.exception.UnsupportedEngineVersionException)2 DefaultHttpMethodRetryHandler (org.apache.commons.httpclient.DefaultHttpMethodRetryHandler)2 NameValuePair (org.apache.commons.httpclient.NameValuePair)2 FileWriter (java.io.FileWriter)1 FilePart (org.apache.commons.httpclient.methods.multipart.FilePart)1 MultipartRequestEntity (org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity)1 Part (org.apache.commons.httpclient.methods.multipart.Part)1 RepositoryContext (org.talend.core.context.RepositoryContext)1 Project (org.talend.core.model.general.Project)1