Refactoring code
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-service@160513 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
1318b67846
commit
84ce8c1853
86
pom.xml
86
pom.xml
|
@ -6,6 +6,7 @@
|
||||||
<artifactId>maven-parent</artifactId>
|
<artifactId>maven-parent</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>org.gcube.accounting</groupId>
|
<groupId>org.gcube.accounting</groupId>
|
||||||
<artifactId>accounting-service</artifactId>
|
<artifactId>accounting-service</artifactId>
|
||||||
<version>1.2.0-SNAPSHOT</version>
|
<version>1.2.0-SNAPSHOT</version>
|
||||||
|
@ -46,93 +47,107 @@
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- smartgears -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.gcube.core</groupId>
|
|
||||||
<artifactId>common-smartgears</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>common-smartgears-app</artifactId>
|
<artifactId>common-smartgears-app</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>authorization-client</artifactId>
|
<artifactId>authorization-client</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>common-authorization</artifactId>
|
<artifactId>common-authorization</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ch.qos.logback</groupId>
|
<groupId>org.gcube.accounting</groupId>
|
||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>accounting-lib</artifactId>
|
||||||
<version>1.0.13</version>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- Used for service query -->
|
||||||
<!-- use for service query -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.accounting</groupId>
|
<groupId>org.gcube.accounting</groupId>
|
||||||
<artifactId>accounting-analytics</artifactId>
|
<artifactId>accounting-analytics</artifactId>
|
||||||
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
|
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.accounting</groupId>
|
<groupId>org.gcube.accounting</groupId>
|
||||||
<artifactId>accounting-analytics-persistence-couchbase</artifactId>
|
<artifactId>accounting-analytics-persistence-couchbase</artifactId>
|
||||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- end use for service query -->
|
<!-- END Used for service query -->
|
||||||
|
<!-- Jersey -->
|
||||||
|
|
||||||
<!-- jersey -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.ws.rs</groupId>
|
<groupId>javax.ws.rs</groupId>
|
||||||
<artifactId>javax.ws.rs-api</artifactId>
|
<artifactId>javax.ws.rs-api</artifactId>
|
||||||
<version>2.0.1</version>
|
<version>2.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.glassfish.jersey.containers</groupId>
|
<groupId>org.glassfish.jersey.containers</groupId>
|
||||||
<artifactId>jersey-container-servlet</artifactId>
|
<artifactId>jersey-container-servlet</artifactId>
|
||||||
<version>2.13</version>
|
<version>2.13</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
<version>3.0.1</version>
|
<version>3.0.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- END Jersey -->
|
||||||
|
<!-- Test Dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.11</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
<version>1.0.13</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
<configuration>
|
|
||||||
<descriptors>
|
|
||||||
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
|
|
||||||
</descriptors>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>servicearchive</id>
|
<id>copy-profile</id>
|
||||||
<phase>install</phase>
|
|
||||||
<goals>
|
<goals>
|
||||||
<goal>single</goal>
|
<goal>copy-resources</goal>
|
||||||
</goals>
|
</goals>
|
||||||
|
<phase>process-resources</phase>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>${webappDirectory}</outputDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>${distroDirectory}</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>make-servicearchive</id>
|
||||||
|
<phase>package</phase>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
@ -142,10 +157,11 @@
|
||||||
<configuration>
|
<configuration>
|
||||||
<warName>${artifactId}</warName>
|
<warName>${artifactId}</warName>
|
||||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||||
|
<!-- webXml>src\main\webapp\WEB-INF\web.xml</webXml -->
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>war</id>
|
<id>servicearchive</id>
|
||||||
<phase>install</phase>
|
<phase>install</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>war</goal>
|
<goal>war</goal>
|
||||||
|
|
|
@ -5,18 +5,18 @@ import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.gcube.data.publishing.accounting.service.resources.ResourceInsert;
|
import org.gcube.data.publishing.accounting.service.resources.ResourceInsert;
|
||||||
import org.glassfish.jersey.server.ResourceConfig;
|
import org.glassfish.jersey.server.ResourceConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Alessandro Pieve (alessandro.pieve@isti.cnr.it)
|
* @author Alessandro Pieve (alessandro.pieve@isti.cnr.it)
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
@ApplicationPath("/")
|
@ApplicationPath("/")
|
||||||
public class AccountingResource extends ResourceConfig{
|
public class AccountingResource extends ResourceConfig {
|
||||||
|
|
||||||
public static final String APPLICATION_JSON_CHARSET_UTF_8 = MediaType.APPLICATION_JSON + ";charset=UTF-8";
|
public static final String APPLICATION_JSON_CHARSET_UTF_8 = MediaType.APPLICATION_JSON + ";charset=UTF-8";
|
||||||
|
|
||||||
public AccountingResource(){
|
public AccountingResource() {
|
||||||
packages(ResourceInsert.class.getPackage().toString());
|
packages(ResourceInsert.class.getPackage().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package org.gcube.data.publishing.accounting.service;
|
package org.gcube.data.publishing.accounting.service;
|
||||||
|
|
||||||
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery;
|
|
||||||
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQueryFactory;
|
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQueryFactory;
|
||||||
import org.gcube.accounting.persistence.AccountingPersistence;
|
|
||||||
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
|
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
|
||||||
import org.gcube.common.authorization.client.Constants;
|
import org.gcube.common.authorization.client.Constants;
|
||||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||||
|
@ -17,23 +15,18 @@ public class AccountingServiceInitializer implements ApplicationManager {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(AccountingServiceInitializer.class);
|
private static Logger logger = LoggerFactory.getLogger(AccountingServiceInitializer.class);
|
||||||
|
|
||||||
// Used for Record insert
|
public static String getCurrentContext() {
|
||||||
protected AccountingPersistence accountingPersistence = null;
|
|
||||||
// Used for Query
|
|
||||||
protected AccountingPersistenceQuery accountingPersistenceQuery;
|
|
||||||
|
|
||||||
public static String getCurrentContext(){
|
|
||||||
String token = SecurityTokenProvider.instance.get();
|
String token = SecurityTokenProvider.instance.get();
|
||||||
AuthorizationEntry authorizationEntry;
|
AuthorizationEntry authorizationEntry;
|
||||||
try {
|
try {
|
||||||
authorizationEntry = Constants.authorizationService().get(token);
|
authorizationEntry = Constants.authorizationService().get(token);
|
||||||
} catch (Exception e) {
|
} catch(Exception e) {
|
||||||
return ScopeProvider.instance.get();
|
return ScopeProvider.instance.get();
|
||||||
}
|
}
|
||||||
return authorizationEntry.getContext();
|
return authorizationEntry.getContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCurrentContext(String token) throws ObjectNotFound, Exception{
|
public static String getCurrentContext(String token) throws ObjectNotFound, Exception {
|
||||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||||
String context = authorizationEntry.getContext();
|
String context = authorizationEntry.getContext();
|
||||||
logger.info("Context of token {} is {}", token, context);
|
logger.info("Context of token {} is {}", token, context);
|
||||||
|
@ -44,63 +37,37 @@ public class AccountingServiceInitializer implements ApplicationManager {
|
||||||
public void onInit() {
|
public void onInit() {
|
||||||
String context = getCurrentContext();
|
String context = getCurrentContext();
|
||||||
|
|
||||||
logger.debug(
|
logger.debug("\n-------------------------------------------------------\n"
|
||||||
"\n-------------------------------------------------------\n"
|
|
||||||
+ "Accounting Service is Starting on context {}\n"
|
+ "Accounting Service is Starting on context {}\n"
|
||||||
+ "-------------------------------------------------------",
|
+ "-------------------------------------------------------", context);
|
||||||
context);
|
|
||||||
// Initializing the persistence connector used for insert
|
// Initializing the persistence connector used for insert
|
||||||
accountingPersistence = AccountingPersistenceFactory.getPersistence();
|
AccountingPersistenceFactory.getPersistence();
|
||||||
accountingPersistenceQuery = AccountingPersistenceQueryFactory.getInstance();
|
// Initializing the persistence connector used for query
|
||||||
|
AccountingPersistenceQueryFactory.getInstance();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onShutdown() {
|
public void onShutdown() {
|
||||||
|
|
||||||
String context = getCurrentContext();
|
String context = getCurrentContext();
|
||||||
logger.trace(
|
logger.trace("\n-------------------------------------------------------\n"
|
||||||
"\n-------------------------------------------------------\n"
|
|
||||||
+ "Accounting Service is Stopping on context {}\n"
|
+ "Accounting Service is Stopping on context {}\n"
|
||||||
+ "-------------------------------------------------------",
|
+ "-------------------------------------------------------", context);
|
||||||
context);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Closing the persistence connector used for insert
|
// Closing the persistence connector used for insert
|
||||||
accountingPersistence.flush();
|
AccountingPersistenceFactory.getPersistence().close();
|
||||||
accountingPersistence.close();
|
|
||||||
|
|
||||||
// Closing the persistence connector used for query
|
// Closing the persistence connector used for query
|
||||||
accountingPersistenceQuery.close();
|
AccountingPersistenceQueryFactory.getInstance().close();
|
||||||
|
|
||||||
|
logger.trace("\n-------------------------------------------------------\n"
|
||||||
logger.trace(
|
|
||||||
"\n-------------------------------------------------------\n"
|
|
||||||
+ "Accounting Service Stopped Successfully on context {}\n"
|
+ "Accounting Service Stopped Successfully on context {}\n"
|
||||||
+ "-------------------------------------------------------",
|
+ "-------------------------------------------------------", context);
|
||||||
context);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch(Exception e) {
|
||||||
logger.error("Error while stopping Accounting Service on context {}", context, e);
|
logger.error("Error while stopping Accounting Service on context {}", context, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return persistence for document store lib
|
|
||||||
*/
|
|
||||||
public AccountingPersistence getAccountingPersistence() {
|
|
||||||
return accountingPersistence;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return persistence for accounting analytics
|
|
||||||
*/
|
|
||||||
public AccountingPersistenceQuery getAccountingPersistenceQuery() {
|
|
||||||
return accountingPersistenceQuery;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import javax.ws.rs.ext.Provider;
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
*/
|
*/
|
||||||
@Provider
|
@Provider
|
||||||
public class AccountingServiceExceptionMapper implements ExceptionMapper<Exception>{
|
public class AccountingServiceExceptionMapper implements ExceptionMapper<Exception> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response toResponse(Exception exception) {
|
public Response toResponse(Exception exception) {
|
||||||
|
|
|
@ -10,15 +10,19 @@ import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
import org.gcube.accounting.persistence.AccountingPersistence;
|
import org.gcube.accounting.persistence.AccountingPersistence;
|
||||||
|
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
|
||||||
import org.gcube.data.publishing.accounting.service.AccountingResource;
|
import org.gcube.data.publishing.accounting.service.AccountingResource;
|
||||||
import org.gcube.data.publishing.accounting.service.AccountingServiceInitializer;
|
import org.gcube.data.publishing.accounting.service.AccountingServiceInitializer;
|
||||||
import org.gcube.documentstore.records.DSMapper;
|
import org.gcube.documentstore.records.DSMapper;
|
||||||
import org.gcube.documentstore.records.Record;
|
import org.gcube.documentstore.records.Record;
|
||||||
import org.gcube.smartgears.ApplicationManagerProvider;
|
|
||||||
import org.gcube.smartgears.annotations.ManagedBy;
|
import org.gcube.smartgears.annotations.ManagedBy;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Alessandro Pieve (alessandro.pieve@isti.cnr.it)
|
||||||
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
*/
|
||||||
@ManagedBy(AccountingServiceInitializer.class)
|
@ManagedBy(AccountingServiceInitializer.class)
|
||||||
@Path(ResourceInsert.INSERT_PATH_PART)
|
@Path(ResourceInsert.INSERT_PATH_PART)
|
||||||
public class ResourceInsert {
|
public class ResourceInsert {
|
||||||
|
@ -30,17 +34,15 @@ public class ResourceInsert {
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path(RECORD_PATH_PART)
|
@Path(RECORD_PATH_PART)
|
||||||
@Consumes({ MediaType.TEXT_PLAIN, AccountingResource.APPLICATION_JSON_CHARSET_UTF_8 })
|
@Consumes({MediaType.TEXT_PLAIN, AccountingResource.APPLICATION_JSON_CHARSET_UTF_8})
|
||||||
public Response add(String json) throws Exception {
|
public Response add(String json) throws Exception {
|
||||||
|
|
||||||
log.debug("Goign to account : {}", json);
|
log.debug("Going to account : {}", json);
|
||||||
|
|
||||||
AccountingServiceInitializer appManager = (AccountingServiceInitializer) ApplicationManagerProvider
|
AccountingPersistence accountingPersistence = AccountingPersistenceFactory.getPersistence();
|
||||||
.get(AccountingServiceInitializer.class);
|
|
||||||
AccountingPersistence accountingPersistence = appManager.getAccountingPersistence();
|
|
||||||
|
|
||||||
List<Record> records = DSMapper.unmarshalList(json);
|
List<Record> records = DSMapper.unmarshalList(json);
|
||||||
for (Record record : records) {
|
for(Record record : records) {
|
||||||
accountingPersistence.account(record);
|
accountingPersistence.account(record);
|
||||||
}
|
}
|
||||||
return Response.status(Status.CREATED).build();
|
return Response.status(Status.CREATED).build();
|
||||||
|
|
|
@ -8,13 +8,17 @@ import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery;
|
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery;
|
||||||
|
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQueryFactory;
|
||||||
import org.gcube.data.publishing.accounting.service.AccountingResource;
|
import org.gcube.data.publishing.accounting.service.AccountingResource;
|
||||||
import org.gcube.data.publishing.accounting.service.AccountingServiceInitializer;
|
import org.gcube.data.publishing.accounting.service.AccountingServiceInitializer;
|
||||||
import org.gcube.smartgears.ApplicationManagerProvider;
|
|
||||||
import org.gcube.smartgears.annotations.ManagedBy;
|
import org.gcube.smartgears.annotations.ManagedBy;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Alessandro Pieve (alessandro.pieve@isti.cnr.it)
|
||||||
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
*/
|
||||||
@ManagedBy(AccountingServiceInitializer.class)
|
@ManagedBy(AccountingServiceInitializer.class)
|
||||||
@Path(ResourceQuery.QUERY_PATH_PART)
|
@Path(ResourceQuery.QUERY_PATH_PART)
|
||||||
public class ResourceQuery {
|
public class ResourceQuery {
|
||||||
|
@ -34,10 +38,7 @@ public class ResourceQuery {
|
||||||
@NotNull @PathParam(RECORD_ID_PATH_PART) String recordId) throws Exception {
|
@NotNull @PathParam(RECORD_ID_PATH_PART) String recordId) throws Exception {
|
||||||
|
|
||||||
log.debug("Requested {} having ID {}", type, recordId);
|
log.debug("Requested {} having ID {}", type, recordId);
|
||||||
|
AccountingPersistenceQuery accountingPersistenceQuery = AccountingPersistenceQueryFactory.getInstance();
|
||||||
AccountingServiceInitializer appManager = (AccountingServiceInitializer) ApplicationManagerProvider
|
|
||||||
.get(AccountingServiceInitializer.class);
|
|
||||||
AccountingPersistenceQuery accountingPersistenceQuery = appManager.getAccountingPersistenceQuery();
|
|
||||||
|
|
||||||
String record = accountingPersistenceQuery.getRecord(recordId, type);
|
String record = accountingPersistenceQuery.getRecord(recordId, type);
|
||||||
return Response.status(200).entity(record).type(AccountingResource.APPLICATION_JSON_CHARSET_UTF_8).build();
|
return Response.status(200).entity(record).type(AccountingResource.APPLICATION_JSON_CHARSET_UTF_8).build();
|
||||||
|
|
|
@ -7,16 +7,21 @@ import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery;
|
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery;
|
||||||
|
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQueryFactory;
|
||||||
import org.gcube.accounting.persistence.AccountingPersistence;
|
import org.gcube.accounting.persistence.AccountingPersistence;
|
||||||
|
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
|
||||||
import org.gcube.data.publishing.accounting.service.AccountingResource;
|
import org.gcube.data.publishing.accounting.service.AccountingResource;
|
||||||
import org.gcube.data.publishing.accounting.service.AccountingServiceInitializer;
|
import org.gcube.data.publishing.accounting.service.AccountingServiceInitializer;
|
||||||
import org.gcube.smartgears.ApplicationManagerProvider;
|
|
||||||
import org.gcube.smartgears.annotations.ManagedBy;
|
import org.gcube.smartgears.annotations.ManagedBy;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Alessandro Pieve (alessandro.pieve@isti.cnr.it)
|
||||||
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
*/
|
||||||
@ManagedBy(AccountingServiceInitializer.class)
|
@ManagedBy(AccountingServiceInitializer.class)
|
||||||
@Path(ServiceState.STATE_PATH_PART)
|
@Path(ServiceState.STATE_PATH_PART)
|
||||||
public class ServiceState {
|
public class ServiceState {
|
||||||
|
@ -44,20 +49,17 @@ public class ServiceState {
|
||||||
|
|
||||||
Status responseStatus = Status.SERVICE_UNAVAILABLE;
|
Status responseStatus = Status.SERVICE_UNAVAILABLE;
|
||||||
|
|
||||||
AccountingServiceInitializer appManager = (AccountingServiceInitializer) ApplicationManagerProvider
|
AccountingPersistence accountingPersistence = AccountingPersistenceFactory.getPersistence();
|
||||||
.get(AccountingServiceInitializer.class);
|
|
||||||
|
|
||||||
AccountingPersistence accountingPersistence = appManager.getAccountingPersistence();
|
|
||||||
try {
|
try {
|
||||||
jsonObject.append(INSERT_CONNECTION_UP, accountingPersistence.isConnectionActive());
|
jsonObject.append(INSERT_CONNECTION_UP, accountingPersistence.isConnectionActive());
|
||||||
}catch (Exception e) {
|
} catch(Exception e) {
|
||||||
jsonObject.append(INSERT_CONNECTION_UP, false);
|
jsonObject.append(INSERT_CONNECTION_UP, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
AccountingPersistenceQuery accountingPersistenceQuery = appManager.getAccountingPersistenceQuery();
|
AccountingPersistenceQuery accountingPersistenceQuery = AccountingPersistenceQueryFactory.getInstance();
|
||||||
try {
|
try {
|
||||||
jsonObject.append(QUERY_CONNECTION_UP, accountingPersistenceQuery.isConnectionActive());
|
jsonObject.append(QUERY_CONNECTION_UP, accountingPersistenceQuery.isConnectionActive());
|
||||||
}catch (Exception e) {
|
} catch(Exception e) {
|
||||||
jsonObject.append(QUERY_CONNECTION_UP, false);
|
jsonObject.append(QUERY_CONNECTION_UP, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,81 +0,0 @@
|
||||||
package org.gcube.data.publishing.accounting.service.utils;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
|
|
||||||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
|
||||||
import org.gcube.documentstore.exception.InvalidValueException;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
public class UtilRecord {
|
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(UtilRecord.class);
|
|
||||||
|
|
||||||
public final static String TEST_CONSUMER_ID = "name.surname";
|
|
||||||
public final static String TEST_SCOPE = "/infrastructure/vo";
|
|
||||||
public final static String TEST_SCOPE_2 = "/infrastructure/vo/vre";
|
|
||||||
public final static OperationResult TEST_OPERATION_RESULT = OperationResult.SUCCESS;
|
|
||||||
|
|
||||||
public final static String TEST_SERVICE_CLASS = "TestServiceClass";
|
|
||||||
public final static String TEST_SERVICE_NAME = "TestServiceName";
|
|
||||||
public final static String TEST_CALLED_METHOD = "TestCalledMethod";
|
|
||||||
public final static String TEST_CALLER_QUALIFIER = "TestCallerQualifier";
|
|
||||||
|
|
||||||
public final static String TEST_CALLER_HOST = "remotehost";
|
|
||||||
public final static String TEST_HOST = "localhost";
|
|
||||||
|
|
||||||
public final static String TEST_PROPERTY_NAME = "TestPropertyName";
|
|
||||||
public final static String TEST_PROPERTY_VALUE = "TestPropertyValue";
|
|
||||||
|
|
||||||
public final static String TEST_JOB_ID = UUID.randomUUID().toString();
|
|
||||||
public final static String TEST_JOB_NAME = "TestJobName";
|
|
||||||
public final static int TEST_VMS_USED = 2;
|
|
||||||
public final static String TEST_JOB_QUALIFIER = "TestJobQualifier";
|
|
||||||
public final static long HALF_DURATION = 10 * 60 * 1000; // 10 min
|
|
||||||
|
|
||||||
public final static String TEST_TASK_ID = UUID.randomUUID().toString();
|
|
||||||
public final static String TEST_NESTED_MAP = "TestNestedMap";
|
|
||||||
|
|
||||||
public final static String TEST_PORTLET_ID = "TestPortlet";
|
|
||||||
public final static String TEST_PORTLET_OPERATION_ID = "TestPortletOperationID";
|
|
||||||
public final static String TEST_PORTLET_MESSAGE = "TestPortletMessage";
|
|
||||||
|
|
||||||
private final static long MIN_DURATION = 60; // millisec
|
|
||||||
private final static long MAX_DURATION = 1000; // millisec
|
|
||||||
/**
|
|
||||||
* Create a valid #ServiceUsageRecord with scope set automatically.
|
|
||||||
* @return the created #ServiceUsageRecord
|
|
||||||
*/
|
|
||||||
public static ServiceUsageRecord createTestServiceUsageRecord() {
|
|
||||||
ServiceUsageRecord usageRecord = new ServiceUsageRecord();
|
|
||||||
try {
|
|
||||||
usageRecord.setConsumerId(TEST_CONSUMER_ID);
|
|
||||||
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
|
|
||||||
|
|
||||||
usageRecord.setCallerHost(TEST_CALLER_HOST);
|
|
||||||
usageRecord.setHost(TEST_HOST);
|
|
||||||
usageRecord.setCallerQualifier(TEST_CALLER_QUALIFIER);
|
|
||||||
usageRecord.setServiceClass(TEST_SERVICE_CLASS);
|
|
||||||
usageRecord.setServiceName(TEST_SERVICE_NAME);
|
|
||||||
usageRecord.setCalledMethod(TEST_CALLED_METHOD);
|
|
||||||
|
|
||||||
usageRecord.setDuration(generateRandomLong(MIN_DURATION, MAX_DURATION));
|
|
||||||
|
|
||||||
} catch (InvalidValueException e) {
|
|
||||||
logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e);
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
return usageRecord;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate A Random long in a range between min and max.
|
|
||||||
* This function is internally used to set random duration.
|
|
||||||
* @return the generated random long
|
|
||||||
*/
|
|
||||||
public static long generateRandomLong(long min, long max){
|
|
||||||
return min + (int)(Math.random() * ((max - min) + 1));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,54 +0,0 @@
|
||||||
package org.gucbe.data.publishing.accounting.service;
|
|
||||||
|
|
||||||
//import org.junit.Test;
|
|
||||||
//import org.slf4j.Logger;
|
|
||||||
//import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
public class JerseyClient {
|
|
||||||
|
|
||||||
//private static Logger log = LoggerFactory.getLogger(JerseyClient.class);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//@Test
|
|
||||||
public void Insert() {
|
|
||||||
/*
|
|
||||||
try {
|
|
||||||
|
|
||||||
Student st = new Student("Adriana", "Barrer", 12, 9);
|
|
||||||
|
|
||||||
ClientConfig clientConfig = new DefaultClientConfig();
|
|
||||||
|
|
||||||
clientConfig.getFeatures().put(
|
|
||||||
JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
|
|
||||||
|
|
||||||
Client client = Client.create(clientConfig);
|
|
||||||
|
|
||||||
WebResource webResource = client
|
|
||||||
.resource("http://localhost:8080/accounting-service/gcube/service/send?gcube-token=3acdde42-6883-4564-b3ba-69f6486f6fe0-98187548");
|
|
||||||
|
|
||||||
ClientResponse response = webResource.accept("application/json")
|
|
||||||
.type("application/json").post(ClientResponse.class, st);
|
|
||||||
|
|
||||||
if (response.getStatus() != 200) {
|
|
||||||
throw new RuntimeException("Failed : HTTP error code : "
|
|
||||||
+ response.getStatus());
|
|
||||||
}
|
|
||||||
|
|
||||||
String output = response.getEntity(String.class);
|
|
||||||
|
|
||||||
System.out.println("Server response .... \n");
|
|
||||||
System.out.println(output);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
e.printStackTrace();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue