Search in sources :

Example 1 with ExportChoice

use of org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice in project tdi-studio-se by Talend.

the class RepositoryService method exportPigudf.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.repository.model.IRepositoryService#exportPigudf(org.talend.designer.runprocess.IProcessor,
     * org.talend.core.model.properties.Property, int, int)
     */
@Override
public String exportPigudf(IProcessor processor, Property property, boolean isExport) throws ProcessorException {
    // build java project
    CorePlugin.getDefault().getRunProcessService().buildJavaProject();
    Map<ExportChoice, Object> exportChoiceMap = new EnumMap<ExportChoice, Object>(ExportChoice.class);
    exportChoiceMap.put(ExportChoice.needPigudf, true);
    ProcessItem processItem = (ProcessItem) property.getItem();
    ExportFileResource fileResource = new ExportFileResource(processItem, property.getLabel());
    ExportFileResource[] exportFileResources = new ExportFileResource[] { fileResource };
    IContext context = processor.getContext();
    //$NON-NLS-1$
    String contextName = "Default";
    if (context != null) {
        contextName = context.getName();
    }
    JobScriptsManager jobScriptsManager = JobScriptsManagerFactory.createManagerInstance(exportChoiceMap, contextName, JobScriptsManager.ALL_ENVIRONMENTS, -1, -1, JobExportType.POJO);
    URL url = jobScriptsManager.getExportPigudfResources(exportFileResources);
    if (url == null) {
        return null;
    }
    File file = new File(url.getFile());
    // String librariesPath = LibrariesManagerUtils.getLibrariesPath(ECodeLanguage.JAVA) + "/";
    //$NON-NLS-1$
    String librariesPath = processor.getCodeProject().getLocation() + "/lib/";
    String targetFileName = JobJavaScriptsManager.USERPIGUDF_JAR;
    if (!isExport) {
        targetFileName = property.getLabel() + '_' + property.getVersion() + '_' + JobJavaScriptsManager.USERPIGUDF_JAR;
    }
    File target = new File(librariesPath + targetFileName);
    try {
        FilesUtils.copyFile(file, target);
    } catch (IOException e) {
        throw new ProcessorException(e.getMessage());
    }
    return targetFileName;
}
Also used : IContext(org.talend.core.model.process.IContext) JobScriptsManager(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager) ProcessorException(org.talend.designer.runprocess.ProcessorException) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) IOException(java.io.IOException) URL(java.net.URL) ProcessItem(org.talend.core.model.properties.ProcessItem) ExportFileResource(org.talend.repository.documentation.ExportFileResource) JSONObject(org.talend.utils.json.JSONObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) SalesforceModuleRepositoryObject(org.talend.core.repository.model.repositoryObject.SalesforceModuleRepositoryObject) EnumMap(java.util.EnumMap) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 2 with ExportChoice

use of org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice in project tdi-studio-se by Talend.

the class JobScriptsExportWizardPage method checkExport.

public boolean checkExport() {
    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) {
        this.setErrorMessage(Messages.getString("JobScriptsExportWizardPage.chooseResource"));
    }
    return canExport;
}
Also used : IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice)

Example 3 with ExportChoice

use of org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice in project tdi-studio-se by Talend.

the class BuildJobHandlerTest method testBuildJob.

@Test
public void testBuildJob() throws Exception {
    Map<ExportChoice, Object> exportChoiceMap = new HashMap<ExportChoice, Object>();
    exportChoiceMap.put(ExportChoice.needLauncher, true);
    exportChoiceMap.put(ExportChoice.needSystemRoutine, true);
    exportChoiceMap.put(ExportChoice.needUserRoutine, true);
    exportChoiceMap.put(ExportChoice.needTalendLibraries, true);
    exportChoiceMap.put(ExportChoice.needJobItem, false);
    exportChoiceMap.put(ExportChoice.needJobScript, true);
    exportChoiceMap.put(ExportChoice.needSourceCode, true);
    exportChoiceMap.put(ExportChoice.includeLibs, true);
    exportChoiceMap.put(ExportChoice.includeTestSource, false);
    exportChoiceMap.put(ExportChoice.executeTests, false);
    exportChoiceMap.put(ExportChoice.binaries, true);
    exportChoiceMap.put(ExportChoice.needContext, true);
    exportChoiceMap.put(ExportChoice.contextName, "Default");
    exportChoiceMap.put(ExportChoice.applyToChildren, false);
    exportChoiceMap.put(ExportChoice.needLog4jLevel, false);
    exportChoiceMap.put(ExportChoice.log4jLevel, null);
    exportChoiceMap.put(ExportChoice.needDependencies, true);
    exportChoiceMap.put(ExportChoice.needParameterValues, false);
    destinationPath = ExportJobUtil.getTmpFolderPath() + "/testBuildJob.zip";
    BuildJobManager.getInstance().buildJob(destinationPath, processItem, "0.1", "Default", exportChoiceMap, JobExportType.POJO, new NullProgressMonitor());
    assertTrue(new File(destinationPath).exists());
    ZipFile zip = null;
    try {
        zip = new ZipFile(destinationPath);
        // jobInfo
        ZipEntry jobInfoEntry = zip.getEntry("jobInfo.properties");
        assertNotNull("Can't find the jobInfo.properties", jobInfoEntry);
        final InputStream jobInfoStream = zip.getInputStream(jobInfoEntry);
        Properties jobInfoProp = new Properties();
        jobInfoProp.load(jobInfoStream);
        assertEquals("testBuildJob", jobInfoProp.getProperty("job"));
        assertEquals("0.1", jobInfoProp.getProperty("jobVersion"));
        assertEquals("Default", jobInfoProp.getProperty("contextName"));
        assertEquals("_bWyBUAYbEeapTZ0aKwL_YA", jobInfoProp.getProperty("jobId"));
        assertEquals("Standard", jobInfoProp.getProperty("jobType"));
        final String technicalLabel = ProjectManager.getInstance().getCurrentProject().getTechnicalLabel();
        assertEquals(technicalLabel, jobInfoProp.getProperty("project"));
        ZipEntry libEntry = zip.getEntry("lib");
        assertNotNull("No lib folder", libEntry);
        // log4j
        ZipEntry log4jXmlEntry = zip.getEntry("testBuildJob/log4j.xml");
        assertNotNull("No log4j.xml", log4jXmlEntry);
        // shell+bat
        ZipEntry batEntry = zip.getEntry("testBuildJob/testBuildJob_run.bat");
        assertNotNull("No bat file", batEntry);
        ZipEntry shEntry = zip.getEntry("testBuildJob/testBuildJob_run.sh");
        assertNotNull("No shell file", shEntry);
        ZipEntry jarEntry = zip.getEntry("testBuildJob/testbuildjob_0_1.jar");
        assertNotNull("No shell file", jarEntry);
        // src
        ZipEntry javaEntry = zip.getEntry("testBuildJob/src/main/java/" + technicalLabel.toLowerCase() + "/testbuildjob_0_1/testBuildJob.java");
        assertNotNull("No job source code file", javaEntry);
        ZipEntry routinesEntry = zip.getEntry("testBuildJob/src/main/java/routines/");
        assertNotNull("No routines source code files", routinesEntry);
        assertTrue(routinesEntry.isDirectory());
        ZipEntry contextEntry = zip.getEntry("testBuildJob/src/main/resources/" + technicalLabel.toLowerCase() + "/testbuildjob_0_1/contexts/Default.properties");
        assertNotNull("No context file", contextEntry);
        // dq
        ZipEntry tdq = zip.getEntry("testBuildJob/items/reports/");
        assertNotNull("Can't find the dq reports items", tdq);
        assertTrue(tdq.isDirectory());
        // if the tdm is load
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ITransformService.class)) {
            ITransformService tdmService = (ITransformService) GlobalServiceRegister.getDefault().getService(ITransformService.class);
            if (tdmService.isTransformItem(processItem)) {
                ZipEntry tdmSettingEntry = zip.getEntry("testBuildJob/items/" + technicalLabel.toLowerCase() + "/.settings/com.oaklandsw.base.projectProps");
                assertNotNull("Can't export tdm rightly", tdmSettingEntry);
                /*
                     * the __tdm has been moved into job jar. so need test it in jar.
                     */
                // ZipEntry tdmEntry = zip.getEntry("testBuildJob/__tdm/");
                // assertNotNull("Can't export tdm rightly", tdmEntry);
                // assertTrue("build job with tdm failure", tdmEntry.isDirectory());
                // testbuildjob_0_1.jar!/__tdm/TEST_NOLOGIN.zip
                final JarInputStream jarStream = new JarInputStream(zip.getInputStream(jarEntry));
                boolean found = false;
                JarEntry entry;
                while ((entry = jarStream.getNextJarEntry()) != null) {
                    final String name = entry.getName();
                    if (name.contains("__tdm") && name.endsWith(technicalLabel + ".zip")) {
                        found = true;
                    }
                }
                jarStream.close();
                assertTrue("Can't find the __tdm in job jar after build", found);
            }
        }
    } finally {
        if (zip != null) {
            zip.close();
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ITransformService(org.talend.core.service.ITransformService) HashMap(java.util.HashMap) JarInputStream(java.util.jar.JarInputStream) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) Properties(java.util.Properties) JarEntry(java.util.jar.JarEntry) ZipFile(java.util.zip.ZipFile) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ZipFile(java.util.zip.ZipFile) File(java.io.File) Test(org.junit.Test)

Example 4 with ExportChoice

use of org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice 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 5 with ExportChoice

use of org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice in project tdi-studio-se by Talend.

the class SpagicDeployWizardPage 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
     */
@Override
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("SpagicDeployWizardPage.exportResourceError"), //$NON-NLS-1$
        Messages.getString("SpagicDeployWizardPage.chooseResource"));
        return false;
    }
    if (!ensureTargetIsValid()) {
        return false;
    }
    manager = new //$NON-NLS-1$
    SpagicJavaDeployManager(//$NON-NLS-1$
    exportChoiceMap, //$NON-NLS-1$
    contextCombo.getText(), //$NON-NLS-1$
    "all", //$NON-NLS-1$
    IProcessor.NO_STATISTICS, IProcessor.NO_TRACES);
    String topFolder = getRootFolderName();
    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));
    // File file = createSapgicProperty();
    ArchiveFileExportOperationFullPath exporterOperation = getExporterOperation(resourcesToExport);
    // exportResource(topFolder, "", "", 1);
    boolean ok = executeExportOperation(exporterOperation);
    // path can like name/name
    manager.deleteTempFiles();
    ProcessorUtilities.resetExportConfig();
    String projectName = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject().getLabel();
    List<JobResource> jobResources = new ArrayList<JobResource>();
    for (ExportFileResource proces : process) {
        try {
            proces.setProcess((ProcessItem) ProxyRepositoryFactory.getInstance().getUptodateProperty(proces.getItem().getProperty()).getItem());
        } catch (PersistenceException e) {
            e.printStackTrace();
        }
        ProcessItem processItem = (ProcessItem) proces.getItem();
        JobInfo jobInfo = new JobInfo(processItem, processItem.getProcess().getDefaultContext());
        jobResources.add(new JobResource(projectName, jobInfo));
        Set<JobInfo> jobInfos = ProcessorUtilities.getChildrenJobInfo(processItem);
        for (JobInfo subjobInfo : jobInfos) {
            jobResources.add(new JobResource(projectName, subjobInfo));
        }
    }
    JobResourceManager reManager = JobResourceManager.getInstance();
    for (JobResource r : jobResources) {
        if (reManager.isProtected(r)) {
            try {
                ProcessorUtilities.generateCode(r.getJobInfo().getJobId(), r.getJobInfo().getContextName(), r.getJobInfo().getJobVersion(), false, false);
            } catch (ProcessorException e) {
                ExceptionHandler.process(e);
            }
        } else {
            reManager.deleteResource(r);
        }
    }
    return ok;
}
Also used : ProcessorException(org.talend.designer.runprocess.ProcessorException) JobResource(org.talend.core.model.repository.job.JobResource) ArrayList(java.util.ArrayList) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) ProcessItem(org.talend.core.model.properties.ProcessItem) ExportFileResource(org.talend.repository.documentation.ExportFileResource) JobInfo(org.talend.core.model.process.JobInfo) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) JobResourceManager(org.talend.core.model.repository.job.JobResourceManager) ArchiveFileExportOperationFullPath(org.talend.core.ui.export.ArchiveFileExportOperationFullPath)

Aggregations

ExportChoice (org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice)18 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)10 File (java.io.File)7 ProcessItem (org.talend.core.model.properties.ProcessItem)7 IOException (java.io.IOException)6 ProcessorException (org.talend.designer.runprocess.ProcessorException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 EnumMap (java.util.EnumMap)4 Map (java.util.Map)4 IFile (org.eclipse.core.resources.IFile)4 IBuildJobHandler (org.talend.core.runtime.process.IBuildJobHandler)4 ExportFileResource (org.talend.repository.documentation.ExportFileResource)4 HashMap (java.util.HashMap)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 PersistenceException (org.talend.commons.exception.PersistenceException)3 JobScriptsManager (org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager)3 URL (java.net.URL)2 Properties (java.util.Properties)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Test (org.junit.Test)2