This commit is contained in:
Ciro Formisano 2018-07-18 09:21:17 +00:00
parent ad712aa95a
commit dc58b53b34
9 changed files with 158 additions and 79 deletions

View File

@ -12,7 +12,7 @@
<groupId>org.gcube.dataAnalysis</groupId> <groupId>org.gcube.dataAnalysis</groupId>
<artifactId>dataminer-pool-manager</artifactId> <artifactId>dataminer-pool-manager</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
<version>2.4.0-SNAPSHOT</version> <version>2.5.0-SNAPSHOT</version>
<name>dataminer-pool-manager</name> <name>dataminer-pool-manager</name>
<description> <description>

View File

@ -5,33 +5,35 @@ import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
***REMOVED*** ***REMOVED***
import java.util.Map; import java.util.Map;
import org.gcube.common.resources.gcore.GenericResource; import org.gcube.common.resources.gcore.GenericResource;
import org.gcube.dataanalysis.dataminer.poolmanager.clients.configuration.ConfigurationImpl.CONFIGURATIONS; import org.gcube.dataanalysis.dataminer.poolmanager.clients.configuration.ConfigurationImpl.CONFIGURATIONS;
import org.gcube.dataanalysis.dataminer.poolmanager.clients.configuration.ConfigurationImpl.REPOSITORIES;
import org.gcube.dataanalysis.dataminer.poolmanager.clients.configurations.AbstractConfiguration; import org.gcube.dataanalysis.dataminer.poolmanager.clients.configurations.AbstractConfiguration;
import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery; import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
***REMOVED***
***REMOVED***
public class ClientConfigurationCache public class ClientConfigurationCache
***REMOVED*** ***REMOVED***
private Map<String, String> repositories; private Logger logger;
private SVNRepository svnRepository;
private Map<String, AbstractConfiguration> configurations; private Map<String, AbstractConfiguration> configurations;
private long svnRepositoryTimeout;
private Map<String, Long> repoTimeouts, private Map<String, Long> configurationsTimeouts;
configurationsTimeouts;
private final long duration = 120000; ***REMOVED***2 minutes private final long duration = 120000; ***REMOVED***2 minutes
public ClientConfigurationCache () ClientConfigurationCache ()
***REMOVED*** ***REMOVED***
this.repositories = new HashMap<>(); this.logger = LoggerFactory.getLogger(ClientConfigurationCache.class);
this.svnRepository = null;
this.configurations = new HashMap<>(); this.configurations = new HashMap<>();
this.repoTimeouts = new HashMap<>(); this.svnRepositoryTimeout = 0;
this.configurationsTimeouts = new HashMap<>(); this.configurationsTimeouts = new HashMap<>();
***REMOVED*** ***REMOVED***
@ -50,40 +52,69 @@ public class ClientConfigurationCache
***REMOVED*** ***REMOVED***
public String getRepository (REPOSITORIES repository) public SVNRepository getSVNRepository ()
***REMOVED*** ***REMOVED***
Long time = this.repoTimeouts.get(repository);
long currentTime = new Date().getTime(); long currentTime = new Date().getTime();
if (time == null || currentTime > time+this.duration) if (this.svnRepositoryTimeout == 0 || currentTime > this.svnRepositoryTimeout+this.duration)
***REMOVED*** ***REMOVED***
this.repositories.put(repository.toString(), getRepository (repository.toString())); this.svnRepository = queryForRepository();
this.repoTimeouts.put(repository.toString(), currentTime); this.svnRepositoryTimeout = currentTime;
***REMOVED*** ***REMOVED***
return this.repositories.get(repository.toString()); return this.svnRepository;
***REMOVED*** ***REMOVED***
private String getRepository(String type) ***REMOVED*** private SVNRepository queryForRepository()
***REMOVED***
String ghost = "";
SimpleQuery query = queryFor(GenericResource.class); SimpleQuery query = queryFor(GenericResource.class);
query.addCondition("$resource/Profile/SecondaryType/text() eq 'DMPMConfigurator'").setResult("$resource"); query.addCondition("$resource/Profile/SecondaryType/text() eq 'DMPMConfigurator'").setResult("$resource");
DiscoveryClient<GenericResource> client = clientFor(GenericResource.class); DiscoveryClient<GenericResource> client = clientFor(GenericResource.class);
List<GenericResource> ds = client.submit(query); List<GenericResource> ds = client.submit(query);
for (GenericResource a : ds) ***REMOVED*** Iterator<GenericResource> resourcesIterator = ds.iterator();
ghost = a.profile().body().getElementsByTagName(type).item(0).getTextContent(); SVNRepository response = null;
while (resourcesIterator.hasNext() && response == null)
***REMOVED***
GenericResource resource = resourcesIterator.next();
String repositoryURL = resource.profile().body().getElementsByTagName(SVNRepository.REPOSITORY_URL).item(0).getTextContent();
if (repositoryURL != null)
***REMOVED***
String repositoryPath = resource.profile().body().getElementsByTagName(SVNRepository.REPOSITORY_PATH).item(0).getTextContent();
String repositoryUsername = null;
String repositoryPassword = null;
try
***REMOVED***
repositoryUsername = resource.profile().body().getElementsByTagName(SVNRepository.REPOSITORY_USERNAME).item(0).getTextContent();
repositoryPassword = resource.profile().body().getElementsByTagName(SVNRepository.REPOSITORY_PASSWORD).item(0).getTextContent();
if (repositoryUsername != null && repositoryUsername.trim() == "") repositoryUsername = null;
if (repositoryPassword != null && repositoryPassword.trim() == "") repositoryPassword = null;
this.logger.debug("Repository username "+repositoryUsername);
this.logger.debug("Repository password "+repositoryPassword);
***REMOVED*** catch (Exception e)
***REMOVED***
this.logger.debug("SVN Username and password not present");
***REMOVED***
this.logger.debug("SVN Repository URL: "+repositoryURL);
this.logger.debug("SVN Repository path: "+repositoryPath);
response = new SVNRepository(repositoryURL, repositoryPath,repositoryUsername, repositoryPassword);
***REMOVED***
***REMOVED*** ***REMOVED***
return ghost.trim ();
***REMOVED***
return response;
***REMOVED*** ***REMOVED***
private AbstractConfiguration getConfiguration (AbstractConfiguration type) private AbstractConfiguration getConfiguration (AbstractConfiguration type)

View File

@ -27,9 +27,7 @@ public interface Configuration ***REMOVED***
public String getSVNWCDepsList(); public String getSVNWCDepsList();
public String getSVNRepository(); public SVNRepository getSVNRepository();
public String getSVNMainAlgoRepo();
public String getGhostAlgoDirectory(); public String getGhostAlgoDirectory();

View File

@ -30,21 +30,21 @@ public class ConfigurationImpl implements Configuration ***REMOVED***
***REMOVED*** ***REMOVED***
enum REPOSITORIES ***REMOVED*** ***REMOVED*** enum REPOSITORIES ***REMOVED***
REPO ("svn.repository"), ***REMOVED*** REPO ("svn.repository"),
MAIN_ALGO ("svn.algo.main.repo"); ***REMOVED*** MAIN_ALGO ("svn.algo.main.repo");
***REMOVED***
private String type; ***REMOVED*** private String type;
***REMOVED***
private REPOSITORIES(String type) ***REMOVED*** ***REMOVED*** private REPOSITORIES(String type) ***REMOVED***
this.type = type; ***REMOVED*** this.type = type;
***REMOVED*** ***REMOVED*** ***REMOVED***
***REMOVED***
***REMOVED*** ***REMOVED******REMOVED***
public String toString() ***REMOVED*** ***REMOVED*** public String toString() ***REMOVED***
return this.type; ***REMOVED*** return this.type;
***REMOVED*** ***REMOVED*** ***REMOVED***
***REMOVED*** ***REMOVED******REMOVED***
private CONFIGURATIONS type; private CONFIGURATIONS type;
@ -129,17 +129,12 @@ public class ConfigurationImpl implements Configuration ***REMOVED***
***REMOVED*** ***REMOVED***
***REMOVED*** ***REMOVED***
public String getSVNRepository() public SVNRepository getSVNRepository()
***REMOVED*** ***REMOVED***
return this.cache.getRepository(REPOSITORIES.REPO); return this.cache.getSVNRepository();
***REMOVED*** ***REMOVED***
***REMOVED***
public String getSVNMainAlgoRepo() ***REMOVED***
return this.cache.getRepository(REPOSITORIES.MAIN_ALGO);
***REMOVED***
***REMOVED*** ***REMOVED***
public String getGhostAlgoDirectory() ***REMOVED*** public String getGhostAlgoDirectory() ***REMOVED***

View File

@ -106,7 +106,7 @@ public class DMPMClientConfiguratorManager
System.out.println("RESULT 1"+a.getStagingConfiguration().getSVNCRANDepsList()); System.out.println("RESULT 1"+a.getStagingConfiguration().getSVNCRANDepsList());
System.out.println("RESULT 2"+a.getProductionConfiguration().getRepository()); System.out.println("RESULT 2"+a.getProductionConfiguration().getRepository());
System.out.println("RESULT 3"+a.getStagingConfiguration().getSVNMainAlgoRepo()); System.out.println("RESULT 3"+a.getStagingConfiguration().getSVNRepository().getPath());
***REMOVED***System.out.println(a.getRepo()); ***REMOVED***System.out.println(a.getRepo());
***REMOVED***System.out.println(a.getAlgoRepo()); ***REMOVED***System.out.println(a.getAlgoRepo());
***REMOVED***System.out.println(a.getSVNRepo()); ***REMOVED***System.out.println(a.getSVNRepo());

View File

@ -0,0 +1,53 @@
package org.gcube.dataanalysis.dataminer.poolmanager.clients.configuration;
public class SVNRepository
***REMOVED***
static final String REPOSITORY_URL = "svn.repository",
REPOSITORY_PATH = "svn.algo.main.repo",
REPOSITORY_USERNAME = "svn.repository.username",
REPOSITORY_PASSWORD = "svn.repository.password";
private String baseUrl,
path,
username,
password;
SVNRepository(String baseUrl, String path, String username, String password) ***REMOVED***
this.baseUrl = baseUrl;
this.path = path;
this.username = username;
this.password = password;
***REMOVED***
SVNRepository(String baseUrl, String path) ***REMOVED***
this (baseUrl, path, null, null);
***REMOVED***
public String getUsername() ***REMOVED***
return username;
***REMOVED***
public void setUsername(String username) ***REMOVED***
this.username = username;
***REMOVED***
public String getPassword() ***REMOVED***
return password;
***REMOVED***
public void setPassword(String password) ***REMOVED***
this.password = password;
***REMOVED***
public String getBaseUrl() ***REMOVED***
return baseUrl;
***REMOVED***
public String getPath() ***REMOVED***
return path;
***REMOVED***
***REMOVED***

View File

@ -6,7 +6,7 @@ import javax.xml.bind.annotation.XmlElement;
public abstract class AbstractConfiguration public abstract class AbstractConfiguration
***REMOVED*** ***REMOVED***
private String host; private String host;
private String algorithmsList; private String algorithmsList;
private String softwareRepo; private String softwareRepo;
private String ghostRepo; private String ghostRepo;
@ -19,11 +19,8 @@ public abstract class AbstractConfiguration
private String depsOctave; private String depsOctave;
private String depsPython; private String depsPython;
private String depsWindowsCompiled; private String depsWindowsCompiled;
@XmlElement (name="host") @XmlElement (name="host")
public String getHost() ***REMOVED*** public String getHost() ***REMOVED***
return host; return host;
@ -47,7 +44,8 @@ public abstract class AbstractConfiguration
public void setSoftwareRepo(String softwareRepo) ***REMOVED*** public void setSoftwareRepo(String softwareRepo) ***REMOVED***
this.softwareRepo = softwareRepo; this.softwareRepo = softwareRepo;
***REMOVED*** ***REMOVED***
@XmlElement (name="ghost-repo") @XmlElement (name="ghost-repo")
public String getGhostRepo() ***REMOVED*** public String getGhostRepo() ***REMOVED***
return ghostRepo; return ghostRepo;

View File

@ -2,6 +2,8 @@ package org.gcube.dataanalysis.dataminer.poolmanager.util;
import org.gcube.dataanalysis.dataminer.poolmanager.clients.configuration.Configuration; import org.gcube.dataanalysis.dataminer.poolmanager.clients.configuration.Configuration;
***REMOVED*** ***REMOVED***
***REMOVED***
***REMOVED***
import org.tmatesoft.svn.core.SVNURL; import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager; import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.io.SVNRepository; import org.tmatesoft.svn.core.io.SVNRepository;
@ -12,11 +14,27 @@ public class SVNRepositoryManager ***REMOVED***
private SVNRepository svnRepository; private SVNRepository svnRepository;
private static SVNRepositoryManager instance; private static SVNRepositoryManager instance;
private Logger logger;
private SVNRepositoryManager (Configuration configuration) throws SVNException private SVNRepositoryManager (Configuration configuration) throws SVNException
***REMOVED*** ***REMOVED***
this.svnRepository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(configuration.getSVNRepository())); this.logger = LoggerFactory.getLogger(SVNRepositoryManager.class);
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(); org.gcube.dataanalysis.dataminer.poolmanager.clients.configuration.SVNRepository repository = configuration.getSVNRepository();
this.svnRepository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(repository.getBaseUrl()));
ISVNAuthenticationManager authManager = null;
if (repository.getUsername() == null)
***REMOVED***
this.logger.debug("Using SVN default credentials");
authManager = SVNWCUtil.createDefaultAuthenticationManager();
***REMOVED***
else
***REMOVED***
this.logger.debug("Using IS credentials");
authManager = SVNWCUtil.createDefaultAuthenticationManager(repository.getUsername(),repository.getPassword());
***REMOVED***
this.svnRepository.setAuthenticationManager(authManager); this.svnRepository.setAuthenticationManager(authManager);
***REMOVED*** ***REMOVED***

View File

@ -12,17 +12,6 @@ public class CheckMethodStaging extends CheckMethod***REMOVED***
***REMOVED*** ***REMOVED***
super (DMPMClientConfiguratorManager.getInstance().getStagingConfiguration()); super (DMPMClientConfiguratorManager.getInstance().getStagingConfiguration());
***REMOVED*** ***REMOVED***
***REMOVED*** ***REMOVED***
protected void copyFromDmToSVN(File a) throws Exception***REMOVED*** protected void copyFromDmToSVN(File a) throws Exception***REMOVED***
@ -30,10 +19,7 @@ public class CheckMethodStaging extends CheckMethod***REMOVED***
***REMOVED*** ***REMOVED***
public static void main(String[] args) throws Exception ***REMOVED*** public static void main(String[] args) throws Exception ***REMOVED***
***REMOVED*** ServiceConfiguration a = new ServiceConfiguration(); ***REMOVED*** ServiceConfiguration a = new ServiceConfiguration();
***REMOVED*** System.out.println(a.getStagingHost()); ***REMOVED*** System.out.println(a.getStagingHost());