get System ServiceEndpoint from IS

This commit is contained in:
Roberto Cirillo 2021-05-07 10:53:57 +02:00
parent 40bd1211ea
commit 702f109cde
4 changed files with 67 additions and 12 deletions

View File

@ -5,4 +5,6 @@
* upgrade mongo-java-driver to 3.12.0 version
* switch from document-store-lib-couchbase to document-sore-lib-accounting-service
* upgrade accounting libraries to 2.0.0 versions
* update JUnit to 4.12
* update JUnit to 4.12
* add oidc-library dep
* switch to UMAToken

View File

@ -167,7 +167,6 @@ public class UserAccountingConsumer extends Thread{
}
}catch(Exception e){
// logger.error(" CATCHED EXCEPTION "+e.getCause().getLocalizedMessage());
logger.error("ERROR Processing record: "+x+" Exception throws: "+e.getMessage());
logger.info("skip to next record ");
if(mongo!=null)

View File

@ -8,7 +8,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.gcube.common.encryption.StringEncrypter;
import org.gcube.common.encryption.encrypter.StringEncrypter;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.resources.gcore.GCoreEndpoint.Profile.Endpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint;
@ -31,10 +31,15 @@ public class Configuration {
private String backendType;
private ArrayList<String> dtsHosts;
private boolean activeDTSFilter;
private static final String SE_CATEGORY="DataStorage";
private static final String SE_NAME="StorageManager";
private static final String STORAGE_SE_CATEGORY="DataStorage";
private static final String STORAGE_SE_NAME="StorageManager";
private static final String SYSTEM_SE_CATEGORY="DataStorage";
private static final String SYSTEM_SE_NAME="StorageManager";
private static final String ACCOUNTING_USERNAME="accounting_user";
private static final String ACCOUNTING_PASSWORDNAME="accounting_pwd";
protected String clientId;
protected String secret;
Logger logger= LoggerFactory.getLogger(Configuration.class);
public Configuration(String scope, String user, String password, boolean dtsFilter){
@ -103,6 +108,14 @@ public class Configuration {
}
return null;
}
protected void setSecrets(ServiceEndpoint se) throws Exception {
for (AccessPoint ap:se.profile().accessPoints()) {
setClientId(ap.username());
setSecret(StringEncrypter.getEncrypter().decrypt(ap.password()));
}
}
/**
* The accounting password is retrieved from the first serviceEndpoint found in the scope and the first accessPoint inside the serviceEndpoint
@ -129,13 +142,25 @@ public class Configuration {
protected List<ServiceEndpoint> getStorageServiceEndpoint() {
logger.debug("query for serviceEndpoint ongoing...");
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Category/text() eq '"+SE_CATEGORY+"' and $resource/Profile/Name eq '"+SE_NAME+"' ");
query.addCondition("$resource/Profile/Category/text() eq '"+STORAGE_SE_CATEGORY+"' and $resource/Profile/Name eq '"+STORAGE_SE_NAME+"' ");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> resources = client.submit(query);
if (resources.size() > 0)
logger.debug("resource found on IS");
return resources;
}
protected ServiceEndpoint getSystemServiceEndpoint() {
logger.debug("query for serviceEndpoint ongoing...");
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Category/text() eq '"+SYSTEM_SE_CATEGORY+"' and $resource/Profile/Name eq '"+SYSTEM_SE_NAME+"' ");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> resources = client.submit(query);
if (resources.size() > 0)
return resources.get(0);
else
throw new RuntimeException("System ServiceEndpoint not found");
}
private String[] getServers(ServiceEndpoint res) {
server=new String[res.profile().accessPoints().size()];
@ -329,7 +354,22 @@ public class Configuration {
this.password = password;
}
public String getClientId() {
return clientId;
}
public void setClientId(String clientId) {
this.clientId = clientId;
}
public String getSecret() {
return secret;
}
public void setSecret(String secret) {
this.secret = secret;
}
}

View File

@ -16,7 +16,10 @@ public class Startup {
private static String accountingUser;
private static String accountingPassword;
private static String scope;
private static List<ServiceEndpoint> se;
private static List<ServiceEndpoint> storage_se;
private static ServiceEndpoint system_se;
private static String clientId;
private static String secret;
public static void main(String[] args) {
@ -41,9 +44,19 @@ public class Startup {
// user=args[2];
// password=args[3];
Configuration cfg=new Configuration(scope, false);
se=cfg.getStorageServiceEndpoint();
accountingUser=cfg.getAccountingUser(se);
accountingPassword=cfg.getAccountingPassword(se);
storage_se=cfg.getStorageServiceEndpoint();
accountingUser=cfg.getAccountingUser(storage_se);
accountingPassword=cfg.getAccountingPassword(storage_se);
system_se=cfg.getSystemServiceEndpoint();
try {
cfg.setSecrets(system_se);
} catch (Exception e) {
System.err.println("problem retrieving credentials from ServiceEnpoint");
e.printStackTrace();
}
clientId=cfg.getClientId();
secret=cfg.getSecret();
String[] server=retrieveServerConfiguration(cfg);
List<String> dtsHosts=null;//retrieveDTSConfiguration(cfg);
@ -54,6 +67,7 @@ public class Startup {
// startFolderAccountingConsumer(args, server, c2);
}
@Deprecated
private static void startFolderAccountingConsumer(String[] args,
String[] server, CubbyHole c2) {
FolderAccountingConsumer fsConsumer=null;
@ -92,7 +106,7 @@ public class Startup {
}
private static String[] retrieveServerConfiguration(Configuration c) {
String[] server= c.getServerAccess(se);
String[] server= c.getServerAccess(storage_se);
if(user == null)
user=c.getUsername();
if(password == null)