Reintroduced ScopeProvider to avoid problem in the next release
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@124138 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
70e0570c82
commit
43c63f2fc6
6
pom.xml
6
pom.xml
|
@ -35,13 +35,13 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.resources.discovery</groupId>
|
||||
<artifactId>ic-client</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-scope</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -53,7 +53,7 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-encryption</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -8,9 +8,7 @@ import java.util.Map;
|
|||
|
||||
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToRecordType;
|
||||
import org.gcube.accounting.datamodel.validations.annotations.ValidOperationResult;
|
||||
import org.gcube.common.authorization.client.Constants;
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.records.implementation.AbstractRecord;
|
||||
import org.gcube.documentstore.records.implementation.RequiredField;
|
||||
|
@ -43,6 +41,7 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe
|
|||
@RequiredField @ValidOperationResult
|
||||
public static final String OPERATION_RESULT = UsageRecord.OPERATION_RESULT;
|
||||
|
||||
/*
|
||||
public static String getScopeFromToken(){
|
||||
String token = SecurityTokenProvider.instance.get();
|
||||
AuthorizationEntry authorizationEntry;
|
||||
|
@ -54,6 +53,7 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe
|
|||
String scope = authorizationEntry.getContext();
|
||||
return scope;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initialize variable
|
||||
|
@ -62,7 +62,8 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe
|
|||
super.init();
|
||||
// Backward compatibility
|
||||
try {
|
||||
this.setScope(getScopeFromToken());
|
||||
//this.setScope(getScopeFromToken());
|
||||
this.setScope(ScopeProvider.instance.get());
|
||||
} catch(Exception e) {
|
||||
logger.warn("Unable to automaticcally set the scope using scope provider. The record will not be valid if the scope will not be explicitly set.");
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ package org.gcube.accounting.persistence;
|
|||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.persistence.PersistenceBackendFactory;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
|
@ -38,7 +38,8 @@ public class AccountingPersistence {
|
|||
* @throws InvalidValueException
|
||||
*/
|
||||
public void account(final Record record) throws InvalidValueException {
|
||||
String scope = BasicUsageRecord.getScopeFromToken();
|
||||
//String scope = BasicUsageRecord.getScopeFromToken();
|
||||
String scope = ScopeProvider.instance.get();
|
||||
try {
|
||||
PersistenceBackendFactory.getPersistenceBackend(scope).account(record);
|
||||
} catch (org.gcube.documentstore.exception.InvalidValueException e) {
|
||||
|
@ -51,12 +52,14 @@ public class AccountingPersistence {
|
|||
}
|
||||
|
||||
public void flush(long timeout, TimeUnit timeUnit) throws Exception {
|
||||
String scope = BasicUsageRecord.getScopeFromToken();
|
||||
//String scope = BasicUsageRecord.getScopeFromToken();
|
||||
String scope = ScopeProvider.instance.get();
|
||||
PersistenceBackendFactory.flush(scope, timeout, timeUnit);
|
||||
}
|
||||
|
||||
public void close() throws Exception{
|
||||
String scope = BasicUsageRecord.getScopeFromToken();
|
||||
//String scope = BasicUsageRecord.getScopeFromToken();
|
||||
String scope = ScopeProvider.instance.get();
|
||||
PersistenceBackendFactory.getPersistenceBackend(scope).close();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,12 +7,12 @@ import java.security.Key;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
||||
import org.gcube.common.encryption.StringEncrypter;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
||||
import org.gcube.common.resources.gcore.utils.Group;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.documentstore.persistence.PersistenceBackend;
|
||||
import org.gcube.documentstore.persistence.PersistenceBackendConfiguration;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
|
@ -58,8 +58,10 @@ public class AccountingPersistenceConfiguration extends PersistenceBackendConfig
|
|||
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
|
||||
List<ServiceEndpoint> serviceEndpoints = client.submit(query);
|
||||
if(serviceEndpoints.size()>1){
|
||||
//String scope = BasicUsageRecord.getScopeFromToken();
|
||||
String scope = ScopeProvider.instance.get();
|
||||
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Name/text() eq '%s'", TARGET_SCOPE));
|
||||
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Value/text() eq '%s'", BasicUsageRecord.getScopeFromToken()));
|
||||
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Value/text() eq '%s'", scope));
|
||||
serviceEndpoints = client.submit(query);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,12 +7,11 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecordTest;
|
||||
import org.gcube.accounting.testutility.ScopedTest;
|
||||
import org.gcube.accounting.testutility.TestUsageRecord;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -21,15 +20,10 @@ import org.slf4j.LoggerFactory;
|
|||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class AggregatedServiceUsageRecordTest {
|
||||
public class AggregatedServiceUsageRecordTest extends ScopedTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(AggregatedServiceUsageRecordTest.class);
|
||||
|
||||
@Before
|
||||
public void before() throws Exception{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException {
|
||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
|
|
|
@ -4,12 +4,11 @@
|
|||
package org.gcube.accounting.datamodel.aggregation;
|
||||
|
||||
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
|
||||
import org.gcube.accounting.testutility.ScopedTest;
|
||||
import org.gcube.accounting.testutility.TestUsageRecord;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -18,15 +17,10 @@ import org.slf4j.LoggerFactory;
|
|||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class AggregatedStorageUsageRecordTest {
|
||||
public class AggregatedStorageUsageRecordTest extends ScopedTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(AggregatedStorageUsageRecordTest.class);
|
||||
|
||||
@Before
|
||||
public void before() throws Exception{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
|
|
|
@ -8,12 +8,11 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractJobUsageRecord;
|
||||
import org.gcube.accounting.testutility.ScopedTest;
|
||||
import org.gcube.accounting.testutility.TestUsageRecord;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -22,15 +21,10 @@ import org.slf4j.LoggerFactory;
|
|||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class JobUsageRecordTest {
|
||||
public class JobUsageRecordTest extends ScopedTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(JobUsageRecordTest.class);
|
||||
|
||||
@Before
|
||||
public void before() throws Exception{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
public static Set<String> getExpectedRequiredFields(){
|
||||
Set<String> expectedRequiredFields = new HashSet<String>();
|
||||
expectedRequiredFields.add(Record.ID);
|
||||
|
|
|
@ -8,12 +8,11 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord;
|
||||
import org.gcube.accounting.testutility.ScopedTest;
|
||||
import org.gcube.accounting.testutility.TestUsageRecord;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -22,15 +21,10 @@ import org.slf4j.LoggerFactory;
|
|||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class ServiceUsageRecordTest {
|
||||
public class ServiceUsageRecordTest extends ScopedTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ServiceUsageRecordTest.class);
|
||||
|
||||
@Before
|
||||
public void before() throws Exception{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
public static Set<String> getExpectedRequiredFields(){
|
||||
Set<String> expectedRequiredFields = new HashSet<String>();
|
||||
expectedRequiredFields.add(Record.ID);
|
||||
|
|
|
@ -8,12 +8,11 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord;
|
||||
import org.gcube.accounting.testutility.ScopedTest;
|
||||
import org.gcube.accounting.testutility.TestUsageRecord;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -22,15 +21,10 @@ import org.slf4j.LoggerFactory;
|
|||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class StorageUsageRecordTest {
|
||||
public class StorageUsageRecordTest extends ScopedTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(StorageUsageRecordTest.class);
|
||||
|
||||
@Before
|
||||
public void before() throws Exception{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
public static Set<String> getExpectedRequiredFields(){
|
||||
Set<String> expectedRequiredFields = new HashSet<String>();
|
||||
expectedRequiredFields.add(Record.ID);
|
||||
|
|
|
@ -8,12 +8,11 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractTaskUsageRecord;
|
||||
import org.gcube.accounting.testutility.ScopedTest;
|
||||
import org.gcube.accounting.testutility.TestUsageRecord;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -22,15 +21,10 @@ import org.slf4j.LoggerFactory;
|
|||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class TaskUsageRecordTest {
|
||||
public class TaskUsageRecordTest extends ScopedTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(TaskUsageRecordTest.class);
|
||||
|
||||
@Before
|
||||
public void before() throws Exception{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
|
||||
public static Set<String> getExpectedRequiredFields(){
|
||||
Set<String> expectedRequiredFields = new HashSet<String>();
|
||||
expectedRequiredFields.add(Record.ID);
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.accounting.testutility;
|
||||
|
||||
//import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.junit.Before;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||
*
|
||||
*/
|
||||
public class ScopedTest {
|
||||
|
||||
@Before
|
||||
public void before() throws Exception{
|
||||
//SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue