Search in sources :

Example 11 with ILibrariesService

use of org.talend.core.model.general.ILibrariesService in project tdq-studio-se by Talend.

the class CorePlugin method initProxyRepository.

/**
 * DOC zshen Comment method "initProxyRepository".
 */
public ReturnCode initProxyRepository() {
    ReturnCode rc = new ReturnCode();
    Project project = null;
    RepositoryContext repositoryContext = (RepositoryContext) org.talend.core.runtime.CoreRuntimePlugin.getInstance().getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY);
    if (repositoryContext != null) {
        project = repositoryContext.getProject();
        User user = repositoryContext.getUser();
        ReponsitoryContextBridge.initialized(project.getEmfProject(), user);
    } else {
        // else project is null, then we are in TOP only
        Location instanceLoc = Platform.getInstanceLocation();
        try {
            if (instanceLoc.isLocked()) {
                // $NON-NLS-1$
                rc.setMessage(DefaultMessagesImpl.getString("CorePlugin.workspaceInUse"));
                rc.setOk(false);
                return rc;
            } else {
                instanceLoc.lock();
            }
        } catch (IOException e) {
            log.error(e, e);
        }
        ProxyRepositoryFactory proxyRepository = ProxyRepositoryFactory.getInstance();
        IRepositoryFactory repository = RepositoryFactoryProvider.getRepositoriyById(RepositoryConstants.REPOSITORY_LOCAL_ID);
        if (repository == null) {
            // $NON-NLS-1$
            log.fatal(DefaultMessagesImpl.getString("CorePlugin.noLocalRepositoryFound"));
            // $NON-NLS-1$
            rc.setMessage(DefaultMessagesImpl.getString("CorePlugin.noLocalRepositoryFound"));
            rc.setOk(false);
            return rc;
        }
        proxyRepository.setRepositoryFactoryFromProvider(repository);
        try {
            proxyRepository.checkAvailability();
            proxyRepository.initialize();
            XmiResourceManager xmiResourceManager = proxyRepository.getRepositoryFactoryFromProvider().getResourceManager();
            IProject rootProject = ResourceManager.getRootProject();
            if (rootProject.getFile(FileConstants.LOCAL_PROJECT_FILENAME).exists()) {
                // Initialize TDQ EMF model packages.
                new EMFUtil();
                project = new Project(xmiResourceManager.loadProject(rootProject));
            } else {
                // $NON-NLS-1$
                String username = "talend@talend.com";
                // $NON-NLS-1$
                String password = "talend@talend.com";
                User user = PropertiesFactoryImpl.eINSTANCE.createUser();
                user.setLogin(username);
                user.setPassword(password.getBytes());
                String projectName = ResourceManager.getRootProjectName();
                String projectDesc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName).getComment();
                Project projectInfor = ProjectHelper.createProject(projectName, projectDesc, ECodeLanguage.JAVA.getName(), user);
                // MOD zshen create project by proxyRepository
                checkFileName(projectInfor.getLabel(), RepositoryConstants.PROJECT_PATTERN);
                project = proxyRepository.getRepositoryFactoryFromProvider().createProject(user, password, projectInfor);
            }
            if (project != null) {
                initRepositoryContext(project);
                // add status
                // $NON-NLS-1$
                String defaultTechnicalStatusList = "DEV development;TEST testing;PROD production";
                List<Status> statusList = StatusHelper.parse(defaultTechnicalStatusList);
                proxyRepository.setTechnicalStatus(statusList);
                // 'maven_user_settings.xml').before set, must check user setting first.
                if (org.talend.commons.utils.platform.PluginChecker.isOnlyTopLoaded()) {
                    if (GlobalServiceRegister.getDefault().isServiceRegistered(IMavenUIService.class)) {
                        IMavenUIService mavenUIService = (IMavenUIService) GlobalServiceRegister.getDefault().getService(IMavenUIService.class);
                        if (mavenUIService != null) {
                            mavenUIService.checkUserSettings(new NullProgressMonitor());
                            mavenUIService.updateMavenResolver(false);
                            mavenUIService.addMavenConfigurationChangeListener();
                        }
                    }
                    // deploy libraries and maven index here
                    if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
                        ILibrariesService librariesService = (ILibrariesService) GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
                        if (librariesService != null) {
                            librariesService.syncLibraries();
                            // TDQ-9529 check libararies install status at here,so that
                            // "Optional third-party libraries" is displayed in the "Additional Talend Package"
                            // dialog.
                            librariesService.checkLibraries();
                        }
                    }
                }
                CWMPlugin.getDefault().createLibFolderIfNotExist();
                // TDQ-11348 the readOnlyUser property is false for TOP.
                // $NON-NLS-1$
                System.getProperties().put("ReadOnlyUser", new Boolean(false).toString());
            }
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            rc.setMessage(e.getMessage());
            rc.setOk(false);
            return rc;
        }
    }
    return rc;
}
Also used : Status(org.talend.core.model.properties.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RepositoryContext(org.talend.core.context.RepositoryContext) IRepositoryFactory(org.talend.core.repository.model.IRepositoryFactory) ReturnCode(org.talend.utils.sugars.ReturnCode) User(org.talend.core.model.properties.User) ILibrariesService(org.talend.core.model.general.ILibrariesService) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) IProject(org.eclipse.core.resources.IProject) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) EMFUtil(org.talend.commons.emf.EMFUtil) PersistenceException(org.talend.commons.exception.PersistenceException) IMavenUIService(org.talend.core.runtime.services.IMavenUIService) Location(org.eclipse.osgi.service.datalocation.Location)

Example 12 with ILibrariesService

use of org.talend.core.model.general.ILibrariesService in project tbd-studio-se by Talend.

the class DistributionVersionModule method getModulesNeeded.

public List<ModuleNeeded> getModulesNeeded() {
    if (modulesNeeded.isEmpty()) {
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
            ILibrariesService libService = (ILibrariesService) GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
            modulesNeeded.addAll(libService.getModuleNeeded(moduleGroup.getModuleName(), true));
        }
    }
    return modulesNeeded;
}
Also used : ILibrariesService(org.talend.core.model.general.ILibrariesService)

Example 13 with ILibrariesService

use of org.talend.core.model.general.ILibrariesService in project tbd-studio-se by Talend.

the class AbstractDynamicDistributionTemplate method unregistPluginExtensions.

@Override
public boolean unregistPluginExtensions(boolean reloadLibCache) {
    if (registedPluginAdapter != null) {
        synchronized (registedPluginAdapterLock) {
            if (registedPluginAdapter != null) {
                try {
                    DynamicServiceUtil.removeContribution(registedPluginAdapter.getPlugin());
                    registedPluginAdapter = null;
                    if (reloadLibCache) {
                        ILibrariesService libService = ILibrariesService.get();
                        if (libService != null) {
                            libService.resetModulesNeeded();
                        }
                    }
                    HadoopDistributionsHelper.updatePluginExtensionCacheVersion();
                    return true;
                } catch (Exception e) {
                    ExceptionHandler.process(e);
                }
            }
        }
    }
    return false;
}
Also used : ILibrariesService(org.talend.core.model.general.ILibrariesService)

Example 14 with ILibrariesService

use of org.talend.core.model.general.ILibrariesService in project tbd-studio-se by Talend.

the class HadoopConfsUtils method buildAndDeployConfsJar.

public static void buildAndDeployConfsJar(HadoopClusterConnectionItem connectionItem, String contextGroup, String dir, String jarName) {
    try {
        File parentFile = new File(getConfsJarTempFolder());
        File jarFile = new File(parentFile, jarName);
        File rootDir = new File(dir);
        JarBuilder jarBuilder = new JarBuilder(rootDir, jarFile);
        jarBuilder.setIncludeDir(null);
        jarBuilder.setExcludeDir(null);
        jarBuilder.buildJar();
        byte[] confFileByteArray = FileUtils.readFileToByteArray(jarFile);
        HadoopClusterConnection connection = (HadoopClusterConnection) connectionItem.getConnection();
        if (connection.isContextMode()) {
            if (contextGroup == null) {
                // $NON-NLS-1$
                throw new Exception("contextGroup cannot be null in context mode!");
            }
            connection.getConfFiles().put(contextGroup, confFileByteArray);
        } else {
            connection.setConfFile(confFileByteArray);
        }
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
            ILibrariesService service = GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
            if (service != null) {
                // Only deploy a new jar, no need to reset all
                service.deployLibrary(jarFile.toURI().toURL());
                addToDeployedCache(connectionItem, jarName);
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : ILibrariesService(org.talend.core.model.general.ILibrariesService) JarBuilder(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JarBuilder) HadoopClusterConnection(org.talend.repository.model.hadoopcluster.HadoopClusterConnection) File(java.io.File) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 15 with ILibrariesService

use of org.talend.core.model.general.ILibrariesService in project tbd-studio-se by Talend.

the class HadoopConfsUtils method createAndDeployConfJar.

private static void createAndDeployConfJar(HadoopClusterConnectionItem connectionItem, String confJarId, String confJarName) throws IOException {
    // If the conf jar has been deployed before then no need to deploy again.
    if (containsInDeployedCache(connectionItem, confJarName)) {
        return;
    }
    byte[] confFileBA = null;
    HadoopClusterConnection connection = (HadoopClusterConnection) connectionItem.getConnection();
    if (connection.isContextMode()) {
        ContextItem contextItem = ContextUtils.getContextItemById2(connection.getContextId());
        if (contextItem != null) {
            EMap<String, byte[]> confFiles = connection.getConfFiles();
            EList<ContextType> contexts = contextItem.getContext();
            for (ContextType contextType : contexts) {
                String contextName = contextType.getName();
                byte[] bs = confFiles.get(contextName);
                if (confJarId.endsWith(contextName) && bs != null) {
                    confFileBA = bs;
                    break;
                }
            }
        }
        if (confFileBA == null) {
            // either conf jar name is wrong or it is a old item.
            // then take the old hadoop conf file content.
            confFileBA = connection.getConfFile();
        }
    } else {
        confFileBA = connection.getConfFile();
    }
    if (confFileBA != null) {
        File confsTempFolder = new File(getConfsJarTempFolder());
        File confFile = new File(confsTempFolder, confJarName);
        FileUtils.writeByteArrayToFile(confFile, confFileBA);
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibraryManagerService.class)) {
            ILibraryManagerService libService = GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
            if (libService != null && libService.isJarNeedToBeDeployed(confFile)) {
                if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
                    ILibrariesService service = GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
                    if (service != null) {
                        // Only deploy a new jar, no need to reset all
                        service.deployLibrary(confFile.toURI().toURL());
                        addToDeployedCache(connectionItem, confJarName);
                    }
                }
            }
        }
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ILibraryManagerService(org.talend.core.ILibraryManagerService) ILibrariesService(org.talend.core.model.general.ILibrariesService) HadoopClusterConnection(org.talend.repository.model.hadoopcluster.HadoopClusterConnection) File(java.io.File)

Aggregations

ILibrariesService (org.talend.core.model.general.ILibrariesService)15 File (java.io.File)7 IOException (java.io.IOException)7 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 InputStream (java.io.InputStream)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Point (org.eclipse.draw2d.geometry.Point)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 INode (org.talend.core.model.process.INode)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 HadoopClusterConnection (org.talend.repository.model.hadoopcluster.HadoopClusterConnection)2 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1