Compare commits
17 Commits
Author | SHA1 | Date |
---|---|---|
Luca Frosini | 6c67cccd63 | |
Luca Frosini | 0c547f14e3 | |
lucio | 7ecf6a2f77 | |
lucio | 3a69a8dfca | |
luca.frosini | 3910ed1bf0 | |
lucio | bdc6998f6d | |
Lucio Lelii | 96979e9289 | |
Luca Frosini | 7c0c1b1c90 | |
Luca Frosini | c7540455d8 | |
Luca Frosini | 9011b0262d | |
Luca Frosini | 5637b3c0af | |
Luca Frosini | 372b5a2e5d | |
Luca Frosini | b2a8885fe3 | |
Luca Frosini | d516325660 | |
Luca Frosini | 248c745e69 | |
Luca Frosini | 841a1e45e6 | |
Luca Frosini | ffb9220fb2 |
|
@ -2,3 +2,4 @@ target
|
|||
.classpath
|
||||
.project
|
||||
/.settings/
|
||||
/.DS_Store
|
||||
|
|
11
CHANGELOG.md
11
CHANGELOG.md
|
@ -2,6 +2,17 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
# Changelog for Accounting Library
|
||||
|
||||
## [v5.0.0-SNAPSHOT]
|
||||
|
||||
- removed old Providers
|
||||
- Added compatibility between smartgears 3 and smartgears 4 component
|
||||
|
||||
|
||||
## [v4.1.0]
|
||||
|
||||
- Deprecated not needed properties to reduce data and improve aggregation
|
||||
- Improved regex to comply with new version of Thredds called methods [#18053]
|
||||
|
||||
|
||||
## [v4.0.0] [r.5.0.0] -
|
||||
|
||||
|
|
24
pom.xml
24
pom.xml
|
@ -5,43 +5,34 @@
|
|||
<parent>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<version>1.2.0</version>
|
||||
</parent>
|
||||
|
||||
<groupId>org.gcube.accounting</groupId>
|
||||
<artifactId>accounting-lib</artifactId>
|
||||
<version>4.0.0</version>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<name>Accounting Library</name>
|
||||
<description>Accounting Library</description>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<serviceClass>Accounting</serviceClass>
|
||||
</properties>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
|
||||
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
|
||||
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
|
||||
</scm>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-bom</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<version>3.0.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.data.publishing</groupId>
|
||||
<artifactId>document-store-lib</artifactId>
|
||||
|
@ -62,7 +53,16 @@
|
|||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>gcube-jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>common-utility-sg4</artifactId>
|
||||
</dependency>
|
||||
<!-- Test Dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.common.security</groupId>
|
||||
<artifactId>gcube-secrets</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
|
|
@ -10,10 +10,7 @@ import java.util.SortedSet;
|
|||
import org.gcube.accounting.datamodel.validations.annotations.ValidOperationResult;
|
||||
import org.gcube.accounting.datamodel.validations.validators.ValidOperationResultValidator;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
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.common.context.ContextUtility;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.records.implementation.AbstractRecord;
|
||||
import org.gcube.documentstore.records.implementation.RequiredField;
|
||||
|
@ -45,23 +42,7 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe
|
|||
@ValidOperationResult
|
||||
public static final String OPERATION_RESULT = UsageRecord.OPERATION_RESULT;
|
||||
|
||||
public static String getContextFromToken() {
|
||||
|
||||
String scope = ScopeProvider.instance.get();
|
||||
if (scope == null) {
|
||||
String token = SecurityTokenProvider.instance.get();
|
||||
|
||||
AuthorizationEntry authorizationEntry;
|
||||
try {
|
||||
authorizationEntry = Constants.authorizationService().get(token);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
scope = authorizationEntry.getContext();
|
||||
}
|
||||
return scope;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize variable
|
||||
*/
|
||||
|
@ -69,10 +50,11 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe
|
|||
super.init();
|
||||
// Backward compatibility
|
||||
try {
|
||||
this.setScope(getContextFromToken());
|
||||
} catch (Exception e) {
|
||||
String context = ContextUtility.getCurrentContextFullName();
|
||||
this.setScope(context);
|
||||
} catch (Throwable t) {
|
||||
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.");
|
||||
"Unable to automatically set the context using the known providers. The record will not be valid if the scope will not be explicitly set.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -116,10 +116,15 @@ public class AggregatedStorageStatusRecord extends AbstractStorageStatusRecord i
|
|||
throws NotAggregatableRecordsExceptions {
|
||||
try {
|
||||
AggregationUtility<AggregatedStorageStatusRecord> aggregationUtility = new AggregationUtility<AggregatedStorageStatusRecord>(this);
|
||||
Calendar thisStartTime = this.getStartTime();
|
||||
aggregationUtility.aggregate(record);
|
||||
this.setDataVolume(record.getDataVolume());
|
||||
this.setDataCount(record.getDataCount());
|
||||
|
||||
|
||||
// Getting the last value
|
||||
if(record.getStartTime().after(thisStartTime)) {
|
||||
this.setDataVolume(record.getDataVolume());
|
||||
this.setDataCount(record.getDataCount());
|
||||
}
|
||||
|
||||
}catch(NotAggregatableRecordsExceptions e){
|
||||
throw e;
|
||||
} catch(Exception ex){
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package org.gcube.accounting.datamodel.backwardcompatibility;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.gcube.documentstore.records.implementation.FieldDecorator;
|
||||
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@FieldDecorator(action=MoveToProviderURIAction.class)
|
||||
public @interface MoveToProviderURI {
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.accounting.datamodel.backwardcompatibility;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractStorageStatusRecord;
|
||||
import org.gcube.accounting.datamodel.validations.validators.ValidURIValidator;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
import org.gcube.documentstore.records.implementation.FieldAction;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*
|
||||
*/
|
||||
public class MoveToProviderURIAction implements FieldAction {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Serializable validate(String key, Serializable value, Record record) throws InvalidValueException {
|
||||
ValidURIValidator validURIValidator = new ValidURIValidator();
|
||||
value = validURIValidator.validate(key, value, record);
|
||||
record.setResourceProperty(AbstractStorageStatusRecord.PROVIDER_URI, (URI) value);
|
||||
return null; //Returning null the initial key is removed from Record
|
||||
}
|
||||
|
||||
}
|
|
@ -8,8 +8,10 @@ import java.net.URI;
|
|||
import java.util.Map;
|
||||
|
||||
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
||||
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToProviderURI;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.DataType;
|
||||
import org.gcube.accounting.datamodel.validations.annotations.FixDataVolumeSign;
|
||||
import org.gcube.accounting.datamodel.validations.annotations.ValidDataTypeVolume;
|
||||
import org.gcube.accounting.datamodel.validations.annotations.ValidDataType;
|
||||
import org.gcube.accounting.datamodel.validations.annotations.ValidURI;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
|
@ -28,10 +30,6 @@ public abstract class AbstractStorageStatusRecord extends BasicUsageRecord {
|
|||
*/
|
||||
private static final long serialVersionUID = -5754343539116896036L;
|
||||
|
||||
public enum DataType {
|
||||
STORAGE, TREE, GEO, DATABASE, LOCAL, OTHER
|
||||
}
|
||||
|
||||
/**
|
||||
* KEY for : Quantity of data in terms of KB
|
||||
*/
|
||||
|
@ -42,39 +40,44 @@ public abstract class AbstractStorageStatusRecord extends BasicUsageRecord {
|
|||
* KEY for : type of data accessed.
|
||||
* The value is a controlled dictionary by StorageStatusRecord.DataType
|
||||
*/
|
||||
@RequiredField @ValidDataTypeVolume
|
||||
@RequiredField @ValidDataType
|
||||
public static final String DATA_TYPE = "dataType";
|
||||
|
||||
/**
|
||||
* KEY for : data Count number of objects
|
||||
*/
|
||||
@RequiredField @NotEmpty
|
||||
@RequiredField @ValidLong @NotEmpty
|
||||
public static final String DATA_COUNT = "dataCount";
|
||||
|
||||
/**
|
||||
* KEY for : data service class identifier
|
||||
*/
|
||||
@RequiredField @NotEmpty
|
||||
@Deprecated
|
||||
public static final String DATA_SERVICECLASS = "dataServiceClass";
|
||||
|
||||
/**
|
||||
* KEY for : data service name identifier
|
||||
*/
|
||||
@RequiredField @NotEmpty
|
||||
@Deprecated
|
||||
public static final String DATA_SERVICENAME = "dataServiceName";
|
||||
|
||||
|
||||
/**
|
||||
* KEY for : data service name id
|
||||
*/
|
||||
@RequiredField @NotEmpty
|
||||
@Deprecated
|
||||
public static final String DATA_SERVICEID = "dataServiceId";
|
||||
|
||||
/**
|
||||
* KEY for : providerId the identifier of the provider which is the target of a read/write operation
|
||||
*/
|
||||
@RequiredField @ValidURI
|
||||
@ValidURI @MoveToProviderURI
|
||||
@Deprecated
|
||||
public static final String PROVIDER_ID = "providerId";
|
||||
|
||||
@RequiredField @ValidURI
|
||||
public static final String PROVIDER_URI = "providerURI";
|
||||
|
||||
|
||||
|
||||
public AbstractStorageStatusRecord() {
|
||||
super();
|
||||
|
@ -118,40 +121,57 @@ public abstract class AbstractStorageStatusRecord extends BasicUsageRecord {
|
|||
setResourceProperty(DATA_COUNT, dataCount);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@JsonIgnore
|
||||
public String getDataServiceClass() {
|
||||
return (String) this.resourceProperties.get(DATA_SERVICECLASS);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setDataServiceClass(String dataServiceClass) throws InvalidValueException {
|
||||
setResourceProperty(DATA_SERVICECLASS, dataServiceClass);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@JsonIgnore
|
||||
public String getDataServiceName() {
|
||||
return (String) this.resourceProperties.get(DATA_SERVICENAME);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setDataServiceName(String dataServiceName) throws InvalidValueException {
|
||||
setResourceProperty(DATA_SERVICENAME, dataServiceName);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@JsonIgnore
|
||||
public String getDataServiceId() {
|
||||
return (String) this.resourceProperties.get(DATA_SERVICEID);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setDataServiceId(String dataServiceId) throws InvalidValueException {
|
||||
setResourceProperty(DATA_SERVICEID, dataServiceId);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Deprecated
|
||||
public URI getProviderId() {
|
||||
return (URI) this.resourceProperties.get(PROVIDER_ID);
|
||||
return (URI) this.resourceProperties.get(PROVIDER_URI);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setProviderId(URI provideId) throws InvalidValueException {
|
||||
setResourceProperty(PROVIDER_ID, provideId);
|
||||
// setResourceProperty(PROVIDER_ID, provideId);
|
||||
setResourceProperty(PROVIDER_URI, provideId);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public URI getProviderURI() {
|
||||
return (URI) this.resourceProperties.get(PROVIDER_URI);
|
||||
}
|
||||
|
||||
public void setProviderURI(URI provideURI) throws InvalidValueException {
|
||||
setResourceProperty(PROVIDER_URI, provideURI);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public abstract class AbstractStorageUsageRecord extends BasicUsageRecord {
|
|||
}
|
||||
|
||||
public enum DataType {
|
||||
STORAGE, TREE, GEO, DATABASE, LOCAL, OTHER
|
||||
STORAGE, TREE, GEO, DATABASE, LOCAL, OTHER, JUPYTER, KUBERNETES
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,18 +42,20 @@ public abstract class AbstractStorageUsageRecord extends BasicUsageRecord {
|
|||
*/
|
||||
@RequiredField @NotEmpty
|
||||
public static final String RESOURCE_OWNER = "resourceOwner";
|
||||
|
||||
/**
|
||||
* KEY for : The Scope where the Resource was stored
|
||||
*/
|
||||
@RequiredField @NotEmpty
|
||||
@Deprecated
|
||||
public static final String RESOURCE_SCOPE = "resourceScope";
|
||||
|
||||
/**
|
||||
* KEY for : The URI of the Stored Resource
|
||||
*/
|
||||
@RequiredField @ValidURI
|
||||
@Deprecated
|
||||
public static final String RESOURCE_URI = "resourceURI";
|
||||
|
||||
|
||||
@RequiredField @ValidURI
|
||||
public static final String PROVIDER_URI = "providerURI";
|
||||
|
||||
|
@ -126,6 +128,7 @@ public abstract class AbstractStorageUsageRecord extends BasicUsageRecord {
|
|||
* Return the scope of the storage resource
|
||||
* @return The scope id of the storage resource
|
||||
*/
|
||||
@Deprecated
|
||||
@JsonIgnore
|
||||
public String getResourceScope() {
|
||||
return (String) this.resourceProperties.get(RESOURCE_SCOPE);
|
||||
|
@ -136,6 +139,7 @@ public abstract class AbstractStorageUsageRecord extends BasicUsageRecord {
|
|||
* @param scope the scope of the storage resource
|
||||
* @throws InvalidValueException
|
||||
*/
|
||||
@Deprecated
|
||||
public void setResourceScope(String scope) throws InvalidValueException {
|
||||
setResourceProperty(RESOURCE_SCOPE, scope);
|
||||
}
|
||||
|
@ -149,11 +153,13 @@ public abstract class AbstractStorageUsageRecord extends BasicUsageRecord {
|
|||
setResourceProperty(PROVIDER_URI, providerURI);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@JsonIgnore
|
||||
public URI getResourceURI() {
|
||||
return (URI) this.resourceProperties.get(RESOURCE_URI);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setResourceURI(URI resourceURI) throws InvalidValueException {
|
||||
setResourceProperty(RESOURCE_URI, resourceURI);
|
||||
}
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
package org.gcube.accounting.datamodel.validations.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.gcube.accounting.datamodel.validations.validators.ValidDataTypeValidatorVolume;
|
||||
import org.gcube.documentstore.records.implementation.FieldDecorator;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@FieldDecorator(action=ValidDataTypeValidatorVolume.class)
|
||||
public @interface ValidDataTypeVolume {
|
||||
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package org.gcube.accounting.datamodel.validations.validators;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractStorageStatusRecord.DataType;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
import org.gcube.documentstore.records.implementation.FieldAction;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class ValidDataTypeValidatorVolume implements FieldAction {
|
||||
|
||||
private static final String ERROR = String.format("Not Instance of %s", DataType.class.getSimpleName());
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public Serializable validate(String key, Serializable value, Record record) throws InvalidValueException {
|
||||
if(value instanceof DataType){
|
||||
return value;
|
||||
}
|
||||
|
||||
try {
|
||||
if(value instanceof String){
|
||||
try{
|
||||
DataType dataType = DataType.valueOf((String) value);
|
||||
if(dataType !=null){
|
||||
return dataType;
|
||||
}
|
||||
} catch(Exception e){
|
||||
// Trying another way
|
||||
}
|
||||
|
||||
try{
|
||||
Integer integer = Integer.getInteger((String) value);
|
||||
if(integer!=null){
|
||||
value = integer;
|
||||
}
|
||||
} catch(Exception e){
|
||||
// Trying another way
|
||||
}
|
||||
}
|
||||
|
||||
if(value instanceof Integer){
|
||||
return DataType.values()[(Integer) value];
|
||||
}
|
||||
|
||||
if(value instanceof Enum){
|
||||
return DataType.values()[((Enum) value).ordinal()];
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
throw new InvalidValueException(ERROR, e);
|
||||
}
|
||||
|
||||
throw new InvalidValueException(ERROR);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@ package org.gcube.accounting.persistence;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
||||
import org.gcube.common.context.ContextUtility;
|
||||
import org.gcube.common.encryption.encrypter.StringEncrypter;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||
|
@ -45,8 +45,9 @@ public class AccountingPersistenceConfiguration extends PersistenceBackendConfig
|
|||
ServiceEndpoint serviceEndpoint = getServiceEndpoint(SERVICE_ENDPOINT_CATEGORY, SERVICE_ENDPOINT_NAME, clz);
|
||||
setValues(serviceEndpoint, clz);
|
||||
}catch (Exception e) {
|
||||
logger.error("Error while instancing {} in context {}", this.getClass().getSimpleName(),
|
||||
BasicUsageRecord.getContextFromToken(), e);
|
||||
String context = ContextUtility.getCurrentContextFullName();
|
||||
logger.error("Error while instancing {} in context {}",
|
||||
this.getClass().getSimpleName(), context, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,7 +66,7 @@ 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.getContextFromToken();
|
||||
String scope = ContextUtility.getCurrentContextFullName();
|
||||
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'", scope));
|
||||
serviceEndpoints = client.submit(query);
|
||||
|
|
|
@ -7,8 +7,6 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.JobUsageRecordTest;
|
||||
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.exception.NotAggregatableRecordsExceptions;
|
||||
import org.gcube.testutility.ContextTest;
|
||||
|
@ -27,8 +25,6 @@ public class AggregatedJobUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
|
||||
JobUsageRecord jobUsageRecord = TestUsageRecord.createTestJobUsageRecord();
|
||||
Assert.assertTrue(jobUsageRecord.getScope()==null);
|
||||
|
@ -56,9 +52,7 @@ public class AggregatedJobUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
|
||||
|
||||
JobUsageRecord jobUsageRecord = TestUsageRecord.createTestJobUsageRecord();
|
||||
Assert.assertTrue(jobUsageRecord.getScope()==null);
|
||||
jobUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
@ -105,8 +99,6 @@ public class AggregatedJobUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void secondAsAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
|
||||
JobUsageRecord jobUsageRecord = TestUsageRecord.createTestJobUsageRecord();
|
||||
Assert.assertTrue(jobUsageRecord.getScope()==null);
|
||||
|
@ -158,8 +150,6 @@ public class AggregatedJobUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
|
||||
JobUsageRecord jobUsageRecord = TestUsageRecord.createTestJobUsageRecord();
|
||||
Assert.assertTrue(jobUsageRecord.getScope()==null);
|
||||
|
|
|
@ -8,8 +8,6 @@ import java.util.Set;
|
|||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecordTest;
|
||||
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||
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.exception.NotAggregatableRecordsExceptions;
|
||||
import org.gcube.documentstore.records.DSMapper;
|
||||
|
@ -30,8 +28,6 @@ public class AggregatedServiceUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
Assert.assertTrue(serviceUsageRecord.getScope()==null);
|
||||
serviceUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
@ -58,8 +54,6 @@ public class AggregatedServiceUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
Assert.assertTrue(serviceUsageRecord.getScope()==null);
|
||||
serviceUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
@ -105,8 +99,6 @@ public class AggregatedServiceUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void secondAsAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
Assert.assertTrue(serviceUsageRecord.getScope()==null);
|
||||
serviceUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
@ -155,8 +147,6 @@ public class AggregatedServiceUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions, JsonProcessingException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
ServiceUsageRecord serviceUsageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
Assert.assertTrue(serviceUsageRecord.getScope()==null);
|
||||
serviceUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
|
|
@ -7,8 +7,6 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.accounting.datamodel.usagerecords.StorageStatusRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.StorageStatusRecordTest;
|
||||
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.exception.NotAggregatableRecordsExceptions;
|
||||
import org.gcube.testutility.ContextTest;
|
||||
|
@ -28,8 +26,6 @@ public class AggregatedStorageStatusRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageStatusRecord storageVolumeUsageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||
Assert.assertTrue(storageVolumeUsageRecord.getScope()==null);
|
||||
storageVolumeUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
@ -52,32 +48,30 @@ public class AggregatedStorageStatusRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageStatusRecord storageVolumeUsageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||
Assert.assertTrue(storageVolumeUsageRecord.getScope()==null);
|
||||
storageVolumeUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
StorageStatusRecord storageStatusUsageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||
Assert.assertTrue(storageStatusUsageRecord.getScope()==null);
|
||||
storageStatusUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
||||
storageVolumeUsageRecord.setResourceProperty(TestUsageRecord.TEST_PROPERTY_NAME, TestUsageRecord.TEST_PROPERTY_VALUE);
|
||||
storageVolumeUsageRecord.validate();
|
||||
logger.debug("StorageVolumeUsageRecord : {}", storageVolumeUsageRecord);
|
||||
storageStatusUsageRecord.setResourceProperty(TestUsageRecord.TEST_PROPERTY_NAME, TestUsageRecord.TEST_PROPERTY_VALUE);
|
||||
storageStatusUsageRecord.validate();
|
||||
logger.debug("StorageVolumeUsageRecord : {}", storageStatusUsageRecord);
|
||||
|
||||
AggregatedStorageStatusRecord aggregated = new AggregatedStorageStatusRecord(storageVolumeUsageRecord);
|
||||
AggregatedStorageStatusRecord aggregated = new AggregatedStorageStatusRecord(storageStatusUsageRecord);
|
||||
logger.debug("StorageVolumeUsageRecord Converted to Aggregated: {}", aggregated);
|
||||
aggregated.validate();
|
||||
|
||||
StorageStatusRecord storageVolumeUsageRecord2 = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||
storageVolumeUsageRecord2.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
StorageStatusRecord storageStatusUsageRecord2 = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||
storageStatusUsageRecord2.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
||||
storageVolumeUsageRecord2.validate();
|
||||
logger.debug("StorageVolumeUsageRecord 2 : {}", storageVolumeUsageRecord2);
|
||||
storageStatusUsageRecord2.validate();
|
||||
logger.debug("StorageVolumeUsageRecord 2 : {}", storageStatusUsageRecord2);
|
||||
|
||||
|
||||
long secondDataVolume = storageVolumeUsageRecord2.getDataVolume();
|
||||
long secondDataVolume = storageStatusUsageRecord2.getDataVolume();
|
||||
|
||||
long secondDataCount = storageVolumeUsageRecord2.getDataCount();
|
||||
long secondDataCount = storageStatusUsageRecord2.getDataCount();
|
||||
|
||||
aggregated.aggregate(storageVolumeUsageRecord2);
|
||||
aggregated.aggregate(storageStatusUsageRecord2);
|
||||
logger.debug("Resulting Aggregated StorageVolumeUsageRecord: {}", aggregated);
|
||||
aggregated.validate();
|
||||
|
||||
|
@ -87,11 +81,14 @@ public class AggregatedStorageStatusRecordTest extends ContextTest {
|
|||
Assert.assertFalse(aggregated.getResourceProperties().containsKey(TestUsageRecord.TEST_PROPERTY_NAME));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void secondAsAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageStatusRecord storageStatusUsageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||
storageStatusUsageRecord.setDataServiceClass("DataServiceClass1");
|
||||
storageStatusUsageRecord.setDataServiceName("DataServiceName1");
|
||||
storageStatusUsageRecord.setDataServiceId("DataServiceId1");
|
||||
|
||||
Assert.assertTrue(storageStatusUsageRecord.getScope()==null);
|
||||
storageStatusUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
storageStatusUsageRecord.validate();
|
||||
|
@ -102,6 +99,10 @@ public class AggregatedStorageStatusRecordTest extends ContextTest {
|
|||
aggregated.validate();
|
||||
|
||||
StorageStatusRecord storageVolumeUsageRecord2 = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||
storageVolumeUsageRecord2.setDataServiceClass("DataServiceClass2");
|
||||
storageVolumeUsageRecord2.setDataServiceName("DataServiceName2");
|
||||
storageVolumeUsageRecord2.setDataServiceId("DataServiceId2");
|
||||
|
||||
Assert.assertTrue(storageVolumeUsageRecord2.getScope()==null);
|
||||
storageVolumeUsageRecord2.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
storageVolumeUsageRecord2.setResourceProperty(TestUsageRecord.TEST_PROPERTY_NAME, TestUsageRecord.TEST_PROPERTY_VALUE);
|
||||
|
@ -129,8 +130,6 @@ public class AggregatedStorageStatusRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageStatusRecord storageVolumeUsageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||
Assert.assertTrue(storageVolumeUsageRecord.getScope()==null);
|
||||
storageVolumeUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
|
|
@ -3,12 +3,11 @@
|
|||
*/
|
||||
package org.gcube.accounting.datamodel.aggregation;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecordTest;
|
||||
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.exception.NotAggregatableRecordsExceptions;
|
||||
import org.gcube.testutility.ContextTest;
|
||||
|
@ -28,8 +27,6 @@ public class AggregatedStorageUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
Assert.assertTrue(storageUsageRecord.getScope()==null);
|
||||
storageUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
@ -52,8 +49,6 @@ public class AggregatedStorageUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
Assert.assertTrue(storageUsageRecord.getScope()==null);
|
||||
storageUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
@ -84,11 +79,13 @@ public class AggregatedStorageUsageRecordTest extends ContextTest {
|
|||
Assert.assertFalse(aggregated.getResourceProperties().containsKey(TestUsageRecord.TEST_PROPERTY_NAME));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void secondAsAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
public void secondAsAggregated() throws Exception {
|
||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
storageUsageRecord.setResourceScope("/gcube");
|
||||
storageUsageRecord.setResourceURI(new URI("resourceURI"));
|
||||
|
||||
Assert.assertTrue(storageUsageRecord.getScope()==null);
|
||||
storageUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
storageUsageRecord.validate();
|
||||
|
@ -99,6 +96,9 @@ public class AggregatedStorageUsageRecordTest extends ContextTest {
|
|||
aggregated.validate();
|
||||
|
||||
StorageUsageRecord storageUsageRecord2 = TestUsageRecord.createTestStorageUsageRecord();
|
||||
storageUsageRecord2.setResourceScope("/gcube/devsec");
|
||||
storageUsageRecord2.setResourceURI(new URI("anotherResourceURI"));
|
||||
|
||||
Assert.assertTrue(storageUsageRecord2.getScope()==null);
|
||||
storageUsageRecord2.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
storageUsageRecord2.setResourceProperty(TestUsageRecord.TEST_PROPERTY_NAME, TestUsageRecord.TEST_PROPERTY_VALUE);
|
||||
|
@ -122,8 +122,6 @@ public class AggregatedStorageUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void aggregationStressTest() throws InvalidValueException, NotAggregatableRecordsExceptions {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
Assert.assertTrue(storageUsageRecord.getScope()==null);
|
||||
storageUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
|
|
@ -8,8 +8,6 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractJobUsageRecord;
|
||||
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.Record;
|
||||
import org.gcube.testutility.ContextTest;
|
||||
|
@ -46,8 +44,6 @@ public class JobUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test(expected=InvalidValueException.class)
|
||||
public void scopeNotSetValidationError() throws InvalidValueException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
JobUsageRecord usageRecord = TestUsageRecord.createTestJobUsageRecord();
|
||||
usageRecord.validate();
|
||||
logger.debug("{}", usageRecord);
|
||||
|
@ -55,8 +51,6 @@ public class JobUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
JobUsageRecord usageRecord = TestUsageRecord.createTestJobUsageRecord();
|
||||
Assert.assertTrue(usageRecord.getScope()==null);
|
||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
|
|
@ -13,8 +13,6 @@ import org.gcube.accounting.datamodel.UsageRecord;
|
|||
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord;
|
||||
import org.gcube.accounting.datamodel.validations.validators.MatcherReplace;
|
||||
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.DSMapper;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
|
@ -53,8 +51,6 @@ public class ServiceUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test(expected=InvalidValueException.class)
|
||||
public void scopeNotSetValidationError() throws InvalidValueException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
ServiceUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
usageRecord.validate();
|
||||
logger.debug("{}", usageRecord);
|
||||
|
@ -62,8 +58,6 @@ public class ServiceUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
ServiceUsageRecord usageRecord = TestUsageRecord.createTestServiceUsageRecord();
|
||||
Assert.assertTrue(usageRecord.getScope()==null);
|
||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
|
|
@ -8,8 +8,6 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractStorageStatusRecord;
|
||||
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.Record;
|
||||
import org.gcube.testutility.ContextTest;
|
||||
|
@ -37,9 +35,6 @@ public class StorageStatusRecordTest extends ContextTest {
|
|||
expectedRequiredFields.add(AbstractStorageStatusRecord.DATA_VOLUME);
|
||||
expectedRequiredFields.add(AbstractStorageStatusRecord.DATA_COUNT);
|
||||
expectedRequiredFields.add(AbstractStorageStatusRecord.DATA_TYPE);
|
||||
expectedRequiredFields.add(AbstractStorageStatusRecord.DATA_SERVICECLASS);
|
||||
expectedRequiredFields.add(AbstractStorageStatusRecord.DATA_SERVICENAME);
|
||||
expectedRequiredFields.add(AbstractStorageStatusRecord.DATA_SERVICEID);
|
||||
expectedRequiredFields.add(AbstractStorageStatusRecord.PROVIDER_ID);
|
||||
|
||||
return expectedRequiredFields;
|
||||
|
@ -47,8 +42,6 @@ public class StorageStatusRecordTest extends ContextTest {
|
|||
|
||||
@Test(expected=InvalidValueException.class)
|
||||
public void scopeNotSetValidationError() throws InvalidValueException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageStatusRecord usageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||
usageRecord.validate();
|
||||
logger.debug("{}", usageRecord);
|
||||
|
@ -56,8 +49,6 @@ public class StorageStatusRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageStatusRecord usageRecord = TestUsageRecord.createTestStorageVolumeUsageRecord();
|
||||
Assert.assertTrue(usageRecord.getScope()==null);
|
||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
|
|
@ -8,8 +8,6 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord;
|
||||
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.Record;
|
||||
import org.gcube.testutility.ContextTest;
|
||||
|
@ -35,8 +33,6 @@ public class StorageUsageRecordTest extends ContextTest {
|
|||
expectedRequiredFields.add(UsageRecord.SCOPE);
|
||||
expectedRequiredFields.add(UsageRecord.OPERATION_RESULT);
|
||||
expectedRequiredFields.add(AbstractStorageUsageRecord.RESOURCE_OWNER);
|
||||
expectedRequiredFields.add(AbstractStorageUsageRecord.RESOURCE_SCOPE);
|
||||
expectedRequiredFields.add(AbstractStorageUsageRecord.RESOURCE_URI);
|
||||
expectedRequiredFields.add(AbstractStorageUsageRecord.PROVIDER_URI);
|
||||
expectedRequiredFields.add(AbstractStorageUsageRecord.OPERATION_TYPE);
|
||||
expectedRequiredFields.add(AbstractStorageUsageRecord.DATA_TYPE);
|
||||
|
@ -47,8 +43,6 @@ public class StorageUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test(expected=InvalidValueException.class)
|
||||
public void scopeNotSetValidationError() throws InvalidValueException {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageUsageRecord usageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
usageRecord.validate();
|
||||
logger.debug("{}", usageRecord);
|
||||
|
@ -56,8 +50,6 @@ public class StorageUsageRecordTest extends ContextTest {
|
|||
|
||||
@Test
|
||||
public void testRequiredFields() throws InvalidValueException{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
StorageUsageRecord usageRecord = TestUsageRecord.createTestStorageUsageRecord();
|
||||
Assert.assertTrue(usageRecord.getScope()==null);
|
||||
usageRecord.setScope(TestUsageRecord.TEST_SCOPE);
|
||||
|
|
|
@ -87,6 +87,7 @@ public class TestRules extends ContextTest {
|
|||
final String requiredMatchesFileName = rulesFile.getName().replaceAll(".json", ".csv");
|
||||
File elaborationFile = new File(rulesDirectory, requiredMatchesFileName);
|
||||
try(BufferedReader br = new BufferedReader(new FileReader(elaborationFile))) {
|
||||
int lineNumber = 1;
|
||||
for(String line; (line = br.readLine()) != null;) {
|
||||
String[] splittedLine = line.split(",");
|
||||
|
||||
|
@ -96,10 +97,10 @@ public class TestRules extends ContextTest {
|
|||
|
||||
Replace replace = matcherReplace.check(serviceClass, serviceName, calledMethod);
|
||||
if(replace != null) {
|
||||
logger.info("{} --> {},{},{}", line, replace.getServiceClass(), replace.getServiceName(),
|
||||
logger.info("line {}: {} --> {},{},{}", lineNumber, line, replace.getServiceClass(), replace.getServiceName(),
|
||||
replace.getCalledMethod());
|
||||
} else {
|
||||
logger.error("{} does not match {}. This MUST not occur.", line,
|
||||
logger.error("{} (line {}) does not match {}. This MUST not occur.", line, lineNumber,
|
||||
matcherReplace.getMultiMatcher().toString());
|
||||
throw new Exception();
|
||||
}
|
||||
|
@ -157,6 +158,8 @@ public class TestRules extends ContextTest {
|
|||
Assert.assertTrue(aggregated.getMaxInvocationTime() == surDuration);
|
||||
}
|
||||
|
||||
++lineNumber;
|
||||
|
||||
}
|
||||
} catch(Exception e) {
|
||||
throw e;
|
||||
|
@ -173,35 +176,42 @@ public class TestRules extends ContextTest {
|
|||
for(File elaborationFileNoMatch : rulesDirectory.listFiles(filenameFilter)) {
|
||||
logger.info("Comparing examples which must not match from file {}", elaborationFileNoMatch.getName());
|
||||
try(BufferedReader br = new BufferedReader(new FileReader(elaborationFileNoMatch))) {
|
||||
int lineCounter = 1;
|
||||
for(String line; (line = br.readLine()) != null;) {
|
||||
String[] splittedLine = line.split(",");
|
||||
String serviceClass = splittedLine[0];
|
||||
String serviceName = splittedLine[1];
|
||||
String calledMethod = splittedLine[2];
|
||||
Replace replace = matcherReplace.check(serviceClass, serviceName, calledMethod);
|
||||
if(replace != null) {
|
||||
logger.error("{} match {} but it should NOT. This MUST not occur.", line,
|
||||
matcherReplace.getMultiMatcher().toString());
|
||||
throw new Exception();
|
||||
} else {
|
||||
logger.trace("{} does NOT match as requested", line, replacementRegex.getServiceClass(),
|
||||
replacementRegex.getServiceName(), replacementRegex.getCalledMethod());
|
||||
}
|
||||
|
||||
ServiceUsageRecord sur = TestUsageRecord.createTestServiceUsageRecord();
|
||||
sur.setServiceClass(serviceClass);
|
||||
sur.setServiceName(serviceName);
|
||||
sur.setCalledMethod(calledMethod);
|
||||
sur.validate();
|
||||
//logger.trace("Should not be aggregated ServiceUsageRecord {}", sur);
|
||||
for(AggregatedServiceUsageRecord asur : aggregatedMap.values()) {
|
||||
try {
|
||||
asur.aggregate(sur);
|
||||
logger.error("The record {} has been aggregated and it should NOT", sur);
|
||||
throw new Exception("The record has been aggregated and it should NOT");
|
||||
} catch(NotAggregatableRecordsExceptions e) {
|
||||
//logger.trace("{} is not aggragable as expected", sur);
|
||||
try {
|
||||
String[] splittedLine = line.split(",");
|
||||
String serviceClass = splittedLine[0];
|
||||
String serviceName = splittedLine[1];
|
||||
String calledMethod = splittedLine[2];
|
||||
Replace replace = matcherReplace.check(serviceClass, serviceName, calledMethod);
|
||||
if(replace != null) {
|
||||
logger.error("{} match {} but it should NOT. This MUST not occur.", line,
|
||||
matcherReplace.getMultiMatcher().toString());
|
||||
throw new Exception();
|
||||
} else {
|
||||
logger.trace("{} does NOT match as requested", line, replacementRegex.getServiceClass(),
|
||||
replacementRegex.getServiceName(), replacementRegex.getCalledMethod());
|
||||
}
|
||||
|
||||
ServiceUsageRecord sur = TestUsageRecord.createTestServiceUsageRecord();
|
||||
sur.setServiceClass(serviceClass);
|
||||
sur.setServiceName(serviceName);
|
||||
sur.setCalledMethod(calledMethod);
|
||||
sur.validate();
|
||||
//logger.trace("Should not be aggregated ServiceUsageRecord {}", sur);
|
||||
for(AggregatedServiceUsageRecord asur : aggregatedMap.values()) {
|
||||
try {
|
||||
asur.aggregate(sur);
|
||||
logger.error("The record {} (line {}) has been aggregated and it should NOT", sur, lineCounter);
|
||||
throw new Exception("The record has been aggregated and it should NOT");
|
||||
} catch(NotAggregatableRecordsExceptions e) {
|
||||
//logger.trace("{} is not aggragable as expected", sur);
|
||||
}
|
||||
}
|
||||
++lineCounter;
|
||||
}catch (Exception e) {
|
||||
logger.error("line {}", lineCounter, e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
} catch(Exception e) {
|
||||
|
@ -227,7 +237,7 @@ public class TestRules extends ContextTest {
|
|||
public void testAllRuleInAdirectory() throws Exception {
|
||||
allRules();
|
||||
File rulesDirectory = getRulesDirectory();
|
||||
File rulesDirFile = new File(rulesDirectory, "perform-service");
|
||||
File rulesDirFile = new File(rulesDirectory, "Thredds");
|
||||
|
||||
FilenameFilter filenameFilter = new FilenameFilter() {
|
||||
@Override
|
||||
|
|
|
@ -23,7 +23,7 @@ public class ValidTimeValidatorTest {
|
|||
@Test
|
||||
public void testClassLong() throws InvalidValueException{
|
||||
ValidLongValidator validTimeValidator = new ValidLongValidator();
|
||||
Long myLong = new Long(4);
|
||||
Long myLong = 4l;
|
||||
validTimeValidator.validate(null, myLong, null);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,14 +7,9 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.gcube.common.authorization.client.Constants;
|
||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||
import org.gcube.common.authorization.library.provider.ClientInfo;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.authorization.library.utils.Caller;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.security.Owner;
|
||||
import org.gcube.common.security.secrets.GCubeSecret;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -67,8 +62,8 @@ public class ContextTest {
|
|||
}
|
||||
|
||||
public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
|
||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||
String context = authorizationEntry.getContext();
|
||||
GCubeSecret secret = new GCubeSecret(token);
|
||||
String context = secret.getContext();
|
||||
logger.info("Context of token {} is {}", token, context);
|
||||
return context;
|
||||
}
|
||||
|
@ -79,14 +74,9 @@ public class ContextTest {
|
|||
}
|
||||
|
||||
private static void setContext(String token) throws ObjectNotFound, Exception {
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||
ClientInfo clientInfo = authorizationEntry.getClientInfo();
|
||||
logger.debug("User : {} - Type : {}", clientInfo.getId(), clientInfo.getType().name());
|
||||
String qualifier = authorizationEntry.getQualifier();
|
||||
Caller caller = new Caller(clientInfo, qualifier);
|
||||
AuthorizationProvider.instance.set(caller);
|
||||
ScopeProvider.instance.set(getCurrentScope(token));
|
||||
GCubeSecret secret = new GCubeSecret(token);
|
||||
Owner clientInfo = secret.getOwner();
|
||||
logger.debug("User : {} - external client? ok: {}", clientInfo.getId(), clientInfo.isExternalClient());
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
|
@ -96,8 +86,6 @@ public class ContextTest {
|
|||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import java.net.URISyntaxException;
|
|||
import java.util.UUID;
|
||||
|
||||
import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractStorageStatusRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord;
|
||||
import org.gcube.accounting.datamodel.usagerecords.PortletUsageRecord;
|
||||
|
@ -95,7 +94,6 @@ public class TestUsageRecord {
|
|||
public final static String TEST_RESOUCE_OWNER = "resource.owner";
|
||||
public final static String TEST_RESOUCE_SCOPE = TEST_SCOPE;
|
||||
|
||||
public final static String TEST_RESOURCE_URI = "testprotocol://objectURI";
|
||||
public final static String TEST_PROVIDER_URI = "testprotocol://providerURI";
|
||||
|
||||
private final static long MIN_DATA_VOLUME = 1024;
|
||||
|
@ -112,9 +110,7 @@ public class TestUsageRecord {
|
|||
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
|
||||
|
||||
usageRecord.setResourceOwner(TEST_RESOUCE_OWNER);
|
||||
usageRecord.setResourceScope(TEST_RESOUCE_SCOPE);
|
||||
|
||||
usageRecord.setResourceURI(new URI(TEST_RESOURCE_URI));
|
||||
usageRecord.setProviderURI(new URI(TEST_PROVIDER_URI));
|
||||
|
||||
usageRecord.setOperationType(AbstractStorageUsageRecord.OperationType.READ);
|
||||
|
@ -137,17 +133,15 @@ public class TestUsageRecord {
|
|||
* Create a valid #StorageVolumeUsageRecord with scope set automatically.
|
||||
* @return the created #StorageVolumeUsageRecord
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public static StorageStatusRecord createTestStorageVolumeUsageRecord() {
|
||||
StorageStatusRecord usageRecord = new StorageStatusRecord();
|
||||
try {
|
||||
usageRecord.setConsumerId(TEST_CONSUMER_ID);
|
||||
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
|
||||
usageRecord.setDataVolume(generateRandomLong(MIN_DATA_VOLUME, MAX_DATA_VOLUME));
|
||||
usageRecord.setDataType(AbstractStorageStatusRecord.DataType.STORAGE);
|
||||
usageRecord.setDataType(AbstractStorageUsageRecord.DataType.STORAGE);
|
||||
usageRecord.setDataCount(generateRandomLong(MIN_DATA_VOLUME, MAX_DATA_VOLUME));
|
||||
usageRecord.setDataServiceClass("dataServiceClass");
|
||||
usageRecord.setDataServiceName("dataServiceName");
|
||||
usageRecord.setDataServiceId("dataServiceId");
|
||||
usageRecord.setProviderId(new URI(TEST_PROVIDER_URI));
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<!-- logger name="org.gcube.documentstore" level="INFO" / -->
|
||||
<!-- logger name="org.gcube.accounting" level="TRACE" / -->
|
||||
<!-- logger name="org.gcube.accounting.datamodel.validations.validators.Harmonizer" level="ERROR" /-->
|
||||
<logger name="org.gcube.accounting.datamodel.validations.validators.TestRules" level="INFO" />
|
||||
<logger name="org.gcube.accounting.datamodel.aggregation" level="TRACE" />
|
||||
|
||||
<root level="WARN">
|
||||
<appender-ref ref="STDOUT" />
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,7 +2,7 @@
|
|||
"match": {
|
||||
"serviceClassRegex": "SDI|DataAnalysis",
|
||||
"serviceNameRegex": "Thredds",
|
||||
"calledMethodRegex": "^(\/){1}(?<Protocol>[a-zA-Z0-9]*){1}(\/public\/netcdf\/){1}(?<Collection>[a-zA-Z0-9_\\-%]*(?<!(..\\.nc)))(\/){1}.*(?<!(..\\.nc|.\\.asc|\\.tiff))$"
|
||||
"calledMethodRegex": "^(\/){1}(thredds\/){0,1}(?<Protocol>[a-zA-Z0-9]*){1}(\/public\/netcdf\/){1}(?<Collection>[a-zA-Z0-9_\\-%]*(?<!(..\\.nc)))(\/){1}.*(?<!(..\\.nc|.\\.asc|\\.tiff))$"
|
||||
},
|
||||
"replace": {
|
||||
"serviceClass": "SDI",
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,7 +2,7 @@
|
|||
"match": {
|
||||
"serviceClassRegex": "SDI|DataAnalysis",
|
||||
"serviceNameRegex": "Thredds",
|
||||
"calledMethodRegex": "^(\/){1}(?<Protocol>[a-zA-Z0-9]*){1}(\/public\/netcdf\/){1}[^\/]*((?<!(..\\.nc|.\\.asc|\\.tiff))|\/wfs)$"
|
||||
"calledMethodRegex": "^(\/){1}(thredds\/){0,1}(?<Protocol>[a-zA-Z0-9]*){1}(\/grid){0,1}(\/public\/netcdf\/){1}[^\/]*((?<!(..\\.nc|.\\.asc|\\.tiff))|((\/wfs)|(\/(pointD|d)ataset\\.(html|xml))))$"
|
||||
},
|
||||
"replace": {
|
||||
"serviceClass": "SDI",
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,7 +2,7 @@
|
|||
"match": {
|
||||
"serviceClassRegex": "SDI|DataAnalysis",
|
||||
"serviceNameRegex": "Thredds",
|
||||
"calledMethodRegex": "^(\/){1}(?<Protocol>[a-zA-Z0-9]*){1}(\/public\/netcdf\/){1}(?<Collection>[a-zA-Z0-9_\\-%]*)(\/){1}(.*\\.(nc|asc|tiff))$"
|
||||
"calledMethodRegex": "^(\/){1}(thredds\/){0,1}(?<Protocol>[a-zA-Z0-9]*){1}(\/public\/netcdf\/){1}(?<Collection>[a-zA-Z0-9_\\-%]*)(\/){1}(.*\\.(nc|asc|tiff))$"
|
||||
},
|
||||
"replace": {
|
||||
"serviceClass": "SDI",
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,7 +2,7 @@
|
|||
"match": {
|
||||
"serviceClassRegex": "SDI|DataAnalysis",
|
||||
"serviceNameRegex": "Thredds",
|
||||
"calledMethodRegex": "^(\/){1}(?<Protocol>[a-zA-Z0-9]*){1}(\/public\/netcdf\/){1}[^\/]*(\\.(nc|asc|tiff))$"
|
||||
"calledMethodRegex": "^(\/){1}(thredds\/){0,1}(?<Protocol>[a-zA-Z0-9]*){1}(\/public\/netcdf\/){1}[^\/]*(\\.(nc|asc|tiff))$"
|
||||
},
|
||||
"replace": {
|
||||
"serviceClass": "SDI",
|
||||
|
|
|
@ -1170,7 +1170,7 @@
|
|||
"match": {
|
||||
"serviceClassRegex": "SDI|DataAnalysis",
|
||||
"serviceNameRegex": "Thredds",
|
||||
"calledMethodRegex": "^(\/){1}(?<Protocol>[a-zA-Z0-9]*){1}(\/public\/netcdf\/){1}(?<Collection>[a-zA-Z0-9_\\-%]*(?<!(..\\.nc)))(\/){1}.*(?<!(..\\.nc|.\\.asc|\\.tiff))$"
|
||||
"calledMethodRegex": "^(\/){1}(thredds\/){0,1}(?<Protocol>[a-zA-Z0-9]*){1}(\/public\/netcdf\/){1}(?<Collection>[a-zA-Z0-9_\\-%]*(?<!(..\\.nc)))(\/){1}.*(?<!(..\\.nc|.\\.asc|\\.tiff))$"
|
||||
},
|
||||
"replace": {
|
||||
"serviceClass": "SDI",
|
||||
|
@ -1181,7 +1181,7 @@
|
|||
"match": {
|
||||
"serviceClassRegex": "SDI|DataAnalysis",
|
||||
"serviceNameRegex": "Thredds",
|
||||
"calledMethodRegex": "^(\/){1}(?<Protocol>[a-zA-Z0-9]*){1}(\/public\/netcdf\/){1}[^\/]*((?<!(..\\.nc|.\\.asc|\\.tiff))|\/wfs)$"
|
||||
"calledMethodRegex": "^(\/){1}(thredds\/){0,1}(?<Protocol>[a-zA-Z0-9]*){1}(\/grid){0,1}(\/public\/netcdf\/){1}[^\/]*((?<!(..\\.nc|.\\.asc|\\.tiff))|((\/wfs)|(\/(pointD|d)ataset\\.(html|xml))))$"
|
||||
},
|
||||
"replace": {
|
||||
"serviceClass": "SDI",
|
||||
|
@ -1203,7 +1203,7 @@
|
|||
"match": {
|
||||
"serviceClassRegex": "SDI|DataAnalysis",
|
||||
"serviceNameRegex": "Thredds",
|
||||
"calledMethodRegex": "^(\/){1}(?<Protocol>[a-zA-Z0-9]*){1}(\/public\/netcdf\/){1}(?<Collection>[a-zA-Z0-9_\\-%]*)(\/){1}(.*\\.(nc|asc|tiff))$"
|
||||
"calledMethodRegex": "^(\/){1}(thredds\/){0,1}(?<Protocol>[a-zA-Z0-9]*){1}(\/public\/netcdf\/){1}(?<Collection>[a-zA-Z0-9_\\-%]*)(\/){1}(.*\\.(nc|asc|tiff))$"
|
||||
},
|
||||
"replace": {
|
||||
"serviceClass": "SDI",
|
||||
|
@ -1214,7 +1214,7 @@
|
|||
"match": {
|
||||
"serviceClassRegex": "SDI|DataAnalysis",
|
||||
"serviceNameRegex": "Thredds",
|
||||
"calledMethodRegex": "^(\/){1}(?<Protocol>[a-zA-Z0-9]*){1}(\/public\/netcdf\/){1}[^\/]*(\\.(nc|asc|tiff))$"
|
||||
"calledMethodRegex": "^(\/){1}(thredds\/){0,1}(?<Protocol>[a-zA-Z0-9]*){1}(\/public\/netcdf\/){1}[^\/]*(\\.(nc|asc|tiff))$"
|
||||
},
|
||||
"replace": {
|
||||
"serviceClass": "SDI",
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue