added accounting features to the pom.xml and code but it doesn't work yet
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@133351 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
095223c0d6
commit
2940e9b9e5
5
pom.xml
5
pom.xml
|
@ -78,6 +78,11 @@
|
||||||
<artifactId>portal-manager</artifactId>
|
<artifactId>portal-manager</artifactId>
|
||||||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.accounting</groupId>
|
||||||
|
<artifactId>accounting-lib</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>common-authorization</artifactId>
|
<artifactId>common-authorization</artifactId>
|
||||||
|
|
|
@ -10,6 +10,10 @@ import javax.ws.rs.core.MultivaluedMap;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.ext.Provider;
|
import javax.ws.rs.ext.Provider;
|
||||||
|
|
||||||
|
import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
|
||||||
|
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
||||||
|
import org.gcube.accounting.persistence.AccountingPersistence;
|
||||||
|
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
|
||||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||||
import org.gcube.common.authorization.library.utils.Caller;
|
import org.gcube.common.authorization.library.utils.Caller;
|
||||||
|
@ -23,10 +27,12 @@ import org.slf4j.LoggerFactory;
|
||||||
* @author Costantino Perciante at ISTI-CNR
|
* @author Costantino Perciante at ISTI-CNR
|
||||||
*/
|
*/
|
||||||
@Provider
|
@Provider
|
||||||
public class RequestsAuthFilter implements ContainerRequestFilter{
|
public class RequestsAuthAccountingFilter implements ContainerRequestFilter{
|
||||||
|
|
||||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(RequestsAuthFilter.class);
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(RequestsAuthAccountingFilter.class);
|
||||||
private static final String AUTH_TOKEN = "gcube-token";
|
private static final String AUTH_TOKEN = "gcube-token";
|
||||||
|
private final static AccountingPersistence accountingPersistence = AccountingPersistenceFactory.getPersistence();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void filter(ContainerRequestContext requestContext)
|
public void filter(ContainerRequestContext requestContext)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
@ -78,11 +84,11 @@ public class RequestsAuthFilter implements ContainerRequestFilter{
|
||||||
* @return null if validation fails
|
* @return null if validation fails
|
||||||
*/
|
*/
|
||||||
private static AuthorizationEntry validateToken(String token){
|
private static AuthorizationEntry validateToken(String token){
|
||||||
|
|
||||||
AuthorizationEntry res = null;
|
AuthorizationEntry res = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// set the root scope
|
// set the root scope
|
||||||
ScopeProvider.instance.set("/" + PortalContext.getConfiguration().getInfrastructureName());
|
ScopeProvider.instance.set("/" + PortalContext.getConfiguration().getInfrastructureName());
|
||||||
logger.debug("Validating token " + token);
|
logger.debug("Validating token " + token);
|
||||||
|
@ -98,5 +104,29 @@ public class RequestsAuthFilter implements ContainerRequestFilter{
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accounts service requests
|
||||||
|
*/
|
||||||
|
private static void accountRequest(String username){
|
||||||
|
|
||||||
|
// Create a new Service Usage Record
|
||||||
|
ServiceUsageRecord usageRecord = new ServiceUsageRecord();
|
||||||
|
|
||||||
|
try{
|
||||||
|
// TODO
|
||||||
|
usageRecord.setResourceProperty(ServiceUsageRecord.CONSUMER_ID, username);
|
||||||
|
usageRecord.setOperationResult(OperationResult.SUCCESS);
|
||||||
|
usageRecord.setCallerHost("node13.d4science.org");
|
||||||
|
usageRecord.setHost("node22.d4science.org");
|
||||||
|
usageRecord.setServiceClass("VREManagement");
|
||||||
|
usageRecord.setServiceName("SmartExecutor");
|
||||||
|
usageRecord.setCalledMethod("launch");
|
||||||
|
usageRecord.setResourceProperty(ServiceUsageRecord.DURATION, "300");
|
||||||
|
accountingPersistence.account(usageRecord);
|
||||||
|
}catch(Exception e){
|
||||||
|
logger.error("Unable to account this service usage record", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue