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;
}
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;
}
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;
}
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);
}
}
}
}
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);
}
}
Aggregations