get System ServiceEndpoint from IS
This commit is contained in:
parent
40bd1211ea
commit
702f109cde
|
@ -5,4 +5,6 @@
|
||||||
* upgrade mongo-java-driver to 3.12.0 version
|
* upgrade mongo-java-driver to 3.12.0 version
|
||||||
* switch from document-store-lib-couchbase to document-sore-lib-accounting-service
|
* switch from document-store-lib-couchbase to document-sore-lib-accounting-service
|
||||||
* upgrade accounting libraries to 2.0.0 versions
|
* 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
|
|
@ -167,7 +167,6 @@ public class UserAccountingConsumer extends Thread{
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
// logger.error(" CATCHED EXCEPTION "+e.getCause().getLocalizedMessage());
|
|
||||||
logger.error("ERROR Processing record: "+x+" Exception throws: "+e.getMessage());
|
logger.error("ERROR Processing record: "+x+" Exception throws: "+e.getMessage());
|
||||||
logger.info("skip to next record ");
|
logger.info("skip to next record ");
|
||||||
if(mongo!=null)
|
if(mongo!=null)
|
||||||
|
|
|
@ -8,7 +8,7 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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;
|
||||||
import org.gcube.common.resources.gcore.GCoreEndpoint.Profile.Endpoint;
|
import org.gcube.common.resources.gcore.GCoreEndpoint.Profile.Endpoint;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
|
@ -31,10 +31,15 @@ public class Configuration {
|
||||||
private String backendType;
|
private String backendType;
|
||||||
private ArrayList<String> dtsHosts;
|
private ArrayList<String> dtsHosts;
|
||||||
private boolean activeDTSFilter;
|
private boolean activeDTSFilter;
|
||||||
private static final String SE_CATEGORY="DataStorage";
|
private static final String STORAGE_SE_CATEGORY="DataStorage";
|
||||||
private static final String SE_NAME="StorageManager";
|
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_USERNAME="accounting_user";
|
||||||
private static final String ACCOUNTING_PASSWORDNAME="accounting_pwd";
|
private static final String ACCOUNTING_PASSWORDNAME="accounting_pwd";
|
||||||
|
protected String clientId;
|
||||||
|
protected String secret;
|
||||||
|
|
||||||
Logger logger= LoggerFactory.getLogger(Configuration.class);
|
Logger logger= LoggerFactory.getLogger(Configuration.class);
|
||||||
|
|
||||||
public Configuration(String scope, String user, String password, boolean dtsFilter){
|
public Configuration(String scope, String user, String password, boolean dtsFilter){
|
||||||
|
@ -103,6 +108,14 @@ public class Configuration {
|
||||||
}
|
}
|
||||||
return null;
|
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
|
* 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() {
|
protected List<ServiceEndpoint> getStorageServiceEndpoint() {
|
||||||
logger.debug("query for serviceEndpoint ongoing...");
|
logger.debug("query for serviceEndpoint ongoing...");
|
||||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
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);
|
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||||
List<ServiceEndpoint> resources = client.submit(query);
|
List<ServiceEndpoint> resources = client.submit(query);
|
||||||
if (resources.size() > 0)
|
if (resources.size() > 0)
|
||||||
logger.debug("resource found on IS");
|
logger.debug("resource found on IS");
|
||||||
return resources;
|
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) {
|
private String[] getServers(ServiceEndpoint res) {
|
||||||
server=new String[res.profile().accessPoints().size()];
|
server=new String[res.profile().accessPoints().size()];
|
||||||
|
@ -329,7 +354,22 @@ public class Configuration {
|
||||||
this.password = password;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,10 @@ public class Startup {
|
||||||
private static String accountingUser;
|
private static String accountingUser;
|
||||||
private static String accountingPassword;
|
private static String accountingPassword;
|
||||||
private static String scope;
|
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) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
@ -41,9 +44,19 @@ public class Startup {
|
||||||
// user=args[2];
|
// user=args[2];
|
||||||
// password=args[3];
|
// password=args[3];
|
||||||
Configuration cfg=new Configuration(scope, false);
|
Configuration cfg=new Configuration(scope, false);
|
||||||
se=cfg.getStorageServiceEndpoint();
|
storage_se=cfg.getStorageServiceEndpoint();
|
||||||
accountingUser=cfg.getAccountingUser(se);
|
accountingUser=cfg.getAccountingUser(storage_se);
|
||||||
accountingPassword=cfg.getAccountingPassword(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);
|
String[] server=retrieveServerConfiguration(cfg);
|
||||||
|
|
||||||
List<String> dtsHosts=null;//retrieveDTSConfiguration(cfg);
|
List<String> dtsHosts=null;//retrieveDTSConfiguration(cfg);
|
||||||
|
@ -54,6 +67,7 @@ public class Startup {
|
||||||
// startFolderAccountingConsumer(args, server, c2);
|
// startFolderAccountingConsumer(args, server, c2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
private static void startFolderAccountingConsumer(String[] args,
|
private static void startFolderAccountingConsumer(String[] args,
|
||||||
String[] server, CubbyHole c2) {
|
String[] server, CubbyHole c2) {
|
||||||
FolderAccountingConsumer fsConsumer=null;
|
FolderAccountingConsumer fsConsumer=null;
|
||||||
|
@ -92,7 +106,7 @@ public class Startup {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String[] retrieveServerConfiguration(Configuration c) {
|
private static String[] retrieveServerConfiguration(Configuration c) {
|
||||||
String[] server= c.getServerAccess(se);
|
String[] server= c.getServerAccess(storage_se);
|
||||||
if(user == null)
|
if(user == null)
|
||||||
user=c.getUsername();
|
user=c.getUsername();
|
||||||
if(password == null)
|
if(password == null)
|
||||||
|
|
Loading…
Reference in New Issue