ProviderURI field set for new accounting system
ReadPreference for mongodb to "secondaryPreferred" Add JUnit test for providerURI field git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/content-management/storage-manager-trigger@119999 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
2bc72bfb52
commit
4fab4ee8b0
|
@ -15,6 +15,8 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ReportAccountingImpl implements Report {
|
||||
private static final String DEFAULT_PRODUCTION_ROOT_SCOPE = "d4science.research-infrastructures.eu";
|
||||
private static final String DEFAULT_PRODUCTION_PROVIDER_URI = "data.d4science.org";
|
||||
final Logger logger = LoggerFactory.getLogger(ReportAccountingImpl.class);
|
||||
// public StorageUsageRecord sur;
|
||||
public AccountingPersistence accountingPersistence;
|
||||
|
@ -68,18 +70,30 @@ import org.slf4j.LoggerFactory;
|
|||
return sur;
|
||||
}
|
||||
|
||||
private StorageUsageRecord setProviderUri(StorageUsageRecord sur, String resourceScope) throws InvalidValueException, URISyntaxException {
|
||||
protected StorageUsageRecord setProviderUri(StorageUsageRecord sur, String resourceScope) throws InvalidValueException, URISyntaxException {
|
||||
logger.debug("retrieve root scope from resourceScope "+resourceScope);
|
||||
String rootScope= resourceScope.substring(1);
|
||||
logger.debug("rootScope extrapolated is: "+rootScope);
|
||||
if(sur == null)
|
||||
sur=new StorageUsageRecord();
|
||||
sur.setProviderURI(new URI(buildProviderURI(resourceScope)));
|
||||
return sur;
|
||||
}
|
||||
|
||||
protected String buildProviderURI(String resourceScope){
|
||||
String rootScope= resourceScope.substring(1);
|
||||
if(resourceScope.contains(DEFAULT_PRODUCTION_ROOT_SCOPE)){
|
||||
providerUri=DEFAULT_PRODUCTION_PROVIDER_URI;
|
||||
return providerUri;
|
||||
}
|
||||
if(rootScope.indexOf("/") != -1){
|
||||
rootScope=rootScope.substring(0, rootScope.indexOf("/"));
|
||||
int i=rootScope.indexOf("/");
|
||||
rootScope=rootScope.substring(0, i);
|
||||
logger.debug("removed sub scopes. rootScope: "+rootScope);
|
||||
}
|
||||
providerUri="data."+rootScope+".org";
|
||||
logger.debug("set provider uri: "+providerUri);
|
||||
sur.setProviderURI(new URI(providerUri));
|
||||
return sur;
|
||||
return providerUri;
|
||||
}
|
||||
|
||||
|
||||
|
@ -163,6 +177,10 @@ import org.slf4j.LoggerFactory;
|
|||
logger.error("Problem on building accounting record: Factory Object is null ");
|
||||
}
|
||||
|
||||
public String getProviderUri() {
|
||||
return providerUri;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ public class ReadingMongoOplog extends Thread{
|
|||
private String password;
|
||||
private int number;
|
||||
private List<String> srvs;
|
||||
protected static ReadPreference READ_PREFERENCE=ReadPreference.primary();
|
||||
protected static ReadPreference READ_PREFERENCE=ReadPreference.secondaryPreferred();
|
||||
protected static final String DEFAULT_DB_NAME="local";
|
||||
|
||||
public ReadingMongoOplog(List<String> srvs, CubbyHole c1, CubbyHole c2, int numberT){
|
||||
|
|
|
@ -36,7 +36,7 @@ public class MongoDB {
|
|||
private static final String DEFAULT_FS_COLLECTION="folderStatus";
|
||||
private FolderStatusOperationManager folderOperationManager;
|
||||
private StorageStatusOperationManager ssOperationManager;
|
||||
protected static ReadPreference READ_PREFERENCE=ReadPreference.primary();
|
||||
protected static ReadPreference READ_PREFERENCE=ReadPreference.secondaryPreferred();
|
||||
protected static final WriteConcern WRITE_TYPE=WriteConcern.REPLICAS_SAFE;
|
||||
|
||||
public MongoDB(String[] server, int port, String user, String password){
|
||||
|
@ -122,7 +122,7 @@ public class MongoDB {
|
|||
}
|
||||
if(mongo==null){
|
||||
logger.debug(" open mongo connection ");
|
||||
MongoClientOptions options=MongoClientOptions.builder().connectionsPerHost(10).socketTimeout(60000).connectTimeout(30000).readPreference(READ_PREFERENCE).build();
|
||||
MongoClientOptions options=MongoClientOptions.builder().connectionsPerHost(10).connectTimeout(30000).readPreference(READ_PREFERENCE).build();
|
||||
if(((pwd != null) && (pwd.length() >0)) && ((user != null) && (user.length() > 0))){
|
||||
MongoCredential credential = MongoCredential.createMongoCRCredential(user, ACCOUNTING_DB, pwd.toCharArray());
|
||||
mongo = new MongoClient(srvList, Arrays.asList(credential), options);
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package org.gcube.contentmanager.storageserver.accounting;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
|
||||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ProviderUriTest {
|
||||
|
||||
ReportAccountingImpl report;
|
||||
private static final String scope="/d4science.research-infrastructures.eu";
|
||||
|
||||
@Before
|
||||
public void init(){
|
||||
|
||||
report = new ReportAccountingImpl();
|
||||
ScopeProvider.instance.set(scope);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
String providerUri= report.buildProviderURI(scope);
|
||||
if(scope.contains("d4science.research-infrastructures.eu"))
|
||||
assertEquals(providerUri, "data.d4science.org");
|
||||
else if(scope.contains("gcube"))
|
||||
assertEquals(providerUri, "data.gcube.org");
|
||||
else
|
||||
System.out.println("provider uri for scope: "+scope+" is "+providerUri);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue