get System ServiceEndpoint from IS
This commit is contained in:
parent
40bd1211ea
commit
702f109cde
|
@ -6,3 +6,5 @@
|
|||
* 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
|
||||
* add oidc-library dep
|
||||
* switch to UMAToken
|
|
@ -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)
|
||||
|
|
|
@ -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){
|
||||
|
@ -104,6 +109,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
|
||||
* @param resources the serviceEndpoint list
|
||||
|
@ -129,7 +142,7 @@ 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)
|
||||
|
@ -137,6 +150,18 @@ public class Configuration {
|
|||
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()];
|
||||
int i=0;
|
||||
|
@ -329,6 +354,21 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue