Search in sources :

Example 41 with HadoopClusterConnection

use of org.talend.repository.model.hadoopcluster.HadoopClusterConnection in project tbd-studio-se by Talend.

the class ChangeHadoopConfJarNameMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    ILibraryManagerService libService = null;
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibraryManagerService.class)) {
        libService = (ILibraryManagerService) GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
    }
    if (libService == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    if (item instanceof HadoopClusterConnectionItem) {
        HadoopClusterConnectionItem hcItem = (HadoopClusterConnectionItem) item;
        HadoopClusterConnection connection = (HadoopClusterConnection) hcItem.getConnection();
        if (connection.getConfFile() == null) {
            String confJarName = HadoopParameterUtil.getConfsJarDefaultName(hcItem.getProperty().getId());
            if (!libService.contains(confJarName)) {
                return ExecutionResult.NOTHING_TO_DO;
            }
            File confsTempFolder = new File(HadoopConfsUtils.getConfsJarTempFolder());
            boolean retrieved = libService.retrieve(confJarName, confsTempFolder.getAbsolutePath(), false);
            File confJarFile = new File(confsTempFolder, confJarName);
            if (retrieved && confJarFile.exists()) {
                try {
                    connection.setConfFile(FileUtils.readFileToByteArray(confJarFile));
                    ProxyRepositoryFactory.getInstance().save(hcItem, true);
                    // Clear cache of the new confs jar name.
                    String newConfJarName = HadoopParameterUtil.getConfsJarDefaultName(hcItem.getProperty().getLabel());
                    HadoopConfsUtils.removeFromDeployedCache(hcItem, newConfJarName);
                    return ExecutionResult.SUCCESS_WITH_ALERT;
                } catch (Exception e) {
                    ExceptionHandler.process(e);
                    return ExecutionResult.FAILURE;
                }
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ILibraryManagerService(org.talend.core.ILibraryManagerService) HadoopClusterConnection(org.talend.repository.model.hadoopcluster.HadoopClusterConnection) HadoopClusterConnectionItem(org.talend.repository.model.hadoopcluster.HadoopClusterConnectionItem) File(java.io.File)

Example 42 with HadoopClusterConnection

use of org.talend.repository.model.hadoopcluster.HadoopClusterConnection in project tbd-studio-se by Talend.

the class HadoopClusterTokenCollector method getTokenDetailsForCurrentProject.

@Override
protected JSONObject getTokenDetailsForCurrentProject() throws Exception {
    JSONObject typesHadoop = new JSONObject();
    for (IRepositoryViewObject rvo : ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.getType(HADOOPCLUSTER))) {
        HadoopClusterConnectionItem item = (HadoopClusterConnectionItem) rvo.getProperty().getItem();
        HadoopClusterConnection connection = (HadoopClusterConnection) item.getConnection();
        // $NON-NLS-1$
        String distrib = connection.getDistribution() + "/" + connection.getDfVersion();
        int nbDbTypes = 1;
        if (typesHadoop.has(distrib)) {
            nbDbTypes = typesHadoop.getInt(distrib);
            nbDbTypes++;
        }
        typesHadoop.put(distrib, nbDbTypes);
    }
    JSONObject hadoopCluster = new JSONObject();
    JSONObject types = new JSONObject();
    types.put("types", typesHadoop);
    hadoopCluster.put(HADOOPCLUSTER, types);
    return hadoopCluster;
}
Also used : JSONObject(us.monoid.json.JSONObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) HadoopClusterConnection(org.talend.repository.model.hadoopcluster.HadoopClusterConnection) HadoopClusterConnectionItem(org.talend.repository.model.hadoopcluster.HadoopClusterConnectionItem)

Example 43 with HadoopClusterConnection

use of org.talend.repository.model.hadoopcluster.HadoopClusterConnection in project tbd-studio-se by Talend.

the class HadoopConfsUtils method updateContextualHadoopConfs.

public static boolean updateContextualHadoopConfs(HadoopClusterConnectionItem hcItem) {
    if (hcItem == null) {
        return false;
    }
    boolean isUpdated = false;
    HadoopClusterConnection connection = (HadoopClusterConnection) hcItem.getConnection();
    if (connection.isContextMode() && connection.isUseCustomConfs()) {
        EMap<String, byte[]> confFiles = connection.getConfFiles();
        byte[] confFile = connection.getConfFile();
        if (confFiles.size() == 0 && confFile != null) {
            ContextItem contextItem = ContextUtils.getContextItemById2(connection.getContextId());
            if (contextItem != null) {
                EList<ContextType> contexts = contextItem.getContext();
                for (ContextType contextType : contexts) {
                    String contextName = contextType.getName();
                    HadoopConfsUtils.getConfsJarDefaultName(hcItem, true, contextName);
                    confFiles.put(contextName, confFile);
                    isUpdated = true;
                }
            }
        }
    }
    return isUpdated;
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) HadoopClusterConnection(org.talend.repository.model.hadoopcluster.HadoopClusterConnection)

Example 44 with HadoopClusterConnection

use of org.talend.repository.model.hadoopcluster.HadoopClusterConnection in project tbd-studio-se by Talend.

the class HadoopClusterRepositoryContentHandler method deleteNode.

@Override
protected void deleteNode(Item item) throws Exception {
    final IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    Project project = new Project(ProjectManager.getInstance().getProject(item.getProperty()));
    HadoopClusterConnectionItem hadoopClusterItem = (HadoopClusterConnectionItem) item;
    HadoopClusterConnection connection = (HadoopClusterConnection) hadoopClusterItem.getConnection();
    List<String> connectionList = connection.getConnectionList();
    for (String connId : connectionList) {
        IRepositoryViewObject repObj = null;
        try {
            repObj = factory.getLastVersion(project, connId);
        } catch (PersistenceException e) {
        // do nothing.
        }
        if (repObj != null) {
            factory.deleteObjectPhysical(repObj);
        }
    }
    connection.getConnectionList().clear();
    factory.save(hadoopClusterItem);
    // Disconnect db connection to hadoop cluster.
    String clusterId = hadoopClusterItem.getProperty().getId();
    List<IRepositoryViewObject> repObjs = ProxyRepositoryFactory.getInstance().getAll(project, ERepositoryObjectType.METADATA_CONNECTIONS);
    for (IRepositoryViewObject repObj : repObjs) {
        if (repObj != null && repObj.getProperty() != null) {
            DatabaseConnectionItem dbItem = (DatabaseConnectionItem) repObj.getProperty().getItem();
            DatabaseConnection dbConnection = (DatabaseConnection) dbItem.getConnection();
            String hcId = dbConnection.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_HADOOP_CLUSTER_ID);
            if (clusterId.equals(hcId)) {
                dbConnection.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_HADOOP_CLUSTER_ID, null);
                factory.save(dbItem);
            }
        }
    }
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) HadoopClusterConnection(org.talend.repository.model.hadoopcluster.HadoopClusterConnection) HadoopClusterConnectionItem(org.talend.repository.model.hadoopcluster.HadoopClusterConnectionItem) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 45 with HadoopClusterConnection

use of org.talend.repository.model.hadoopcluster.HadoopClusterConnection in project tbd-studio-se by Talend.

the class HCRepositoryUtil method setupConnectionToHadoopCluster.

public static void setupConnectionToHadoopCluster(HadoopClusterConnectionItem hcConnectionItem, String connectionID) throws PersistenceException {
    if (hcConnectionItem != null) {
        HadoopClusterConnection clusterConnection = (HadoopClusterConnection) hcConnectionItem.getConnection();
        clusterConnection.getConnectionList().add(connectionID);
        ProxyRepositoryFactory.getInstance().save(hcConnectionItem);
    }
}
Also used : HadoopClusterConnection(org.talend.repository.model.hadoopcluster.HadoopClusterConnection)

Aggregations

HadoopClusterConnection (org.talend.repository.model.hadoopcluster.HadoopClusterConnection)78 HadoopClusterConnectionItem (org.talend.repository.model.hadoopcluster.HadoopClusterConnectionItem)30 Test (org.junit.Test)15 ContextItem (org.talend.core.model.properties.ContextItem)14 ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)13 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)9 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 Item (org.talend.core.model.properties.Item)7 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)7 DistributionBean (org.talend.hadoop.distribution.model.DistributionBean)7 ConnectionItem (org.talend.core.model.properties.ConnectionItem)6 HadoopSubConnectionItem (org.talend.repository.model.hadoopcluster.HadoopSubConnectionItem)6 File (java.io.File)5 IHDistributionVersion (org.talend.core.runtime.hd.IHDistributionVersion)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 List (java.util.List)4 PersistenceException (org.talend.commons.exception.PersistenceException)4 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)4