git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/resource-management/quota-manager@144093 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
0f90d103d3
commit
fac6d3ef49
|
@ -322,6 +322,57 @@ public class QuotaUsage {
|
|||
return quotaStorageStatus;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* selectStorageQuotaList list of quota storage
|
||||
* @param identifier
|
||||
* @param interval
|
||||
* @return Quota Storage Status
|
||||
* @throws Exception
|
||||
*/
|
||||
public List<QuotaStorageStatus> selectStorageQuotaList(TimeInterval interval)throws Exception {
|
||||
|
||||
Connection connection = getDBConnection();
|
||||
List<QuotaStorageStatus> quotaStorageStatusList=new ArrayList<QuotaStorageStatus>();
|
||||
Statement stmt = null;
|
||||
try {
|
||||
connection.setAutoCommit(false);
|
||||
stmt = connection.createStatement();
|
||||
String periodQuota=ConstantsDb.DATABASE_PERIOD_TOTAL;
|
||||
Double quotaAssigned = 0.0;
|
||||
Double quotaUsage=0.0;
|
||||
String identifier;
|
||||
//Quota Storage Total
|
||||
if (interval.equals(TimeInterval.FOREVER)){
|
||||
String query="SELECT * FROM "+ConstantsDb.DATABASE_PREFIX+ConstantsDb.SEPARATOR+ConstantsDb.DATABASE_TYPE_STORAGE+ConstantsDb.SEPARATOR+periodQuota+" order by QUOTAUSAGE DESC";
|
||||
ResultSet rs = stmt.executeQuery(query);
|
||||
|
||||
while (rs.next()) {
|
||||
quotaAssigned=rs.getDouble("QUOTAASSIGNED");
|
||||
quotaUsage=rs.getDouble("QUOTAUSAGE");
|
||||
identifier=rs.getString("IDENTIFIER");
|
||||
quotaStorageStatusList.add(new QuotaStorageStatus(identifier,interval,quotaAssigned,quotaUsage));
|
||||
}
|
||||
}
|
||||
|
||||
stmt.close();
|
||||
connection.commit();
|
||||
|
||||
} catch (SQLException e) {
|
||||
log.error("Sql error Message " + e);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Exception error Message " + e);
|
||||
|
||||
} finally {
|
||||
connection.close();
|
||||
}
|
||||
return quotaStorageStatusList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if exist a table
|
||||
* @param connection
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.gcube.resource.management.quota.manager.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
|
@ -55,6 +57,29 @@ public class QuotaStatus {
|
|||
}
|
||||
return quotaStorageStatus;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//http://.....quota-manager/gcube/service/quotaStatus/list/?timeinterval=MONTHLY&gcube-token=...
|
||||
@GET
|
||||
@Path("/list/")
|
||||
@Produces(MediaType.APPLICATION_XML)
|
||||
public List<QuotaStorageStatus> getQuotaStorageStatusList(@QueryParam("timeinterval") String timeinterval) {
|
||||
QuotaUsage queryUsage =appManager.getQuotaUsage();
|
||||
|
||||
List<QuotaStorageStatus> quotaStorageStatusList;
|
||||
try{
|
||||
quotaStorageStatusList=queryUsage.selectStorageQuotaList(TimeInterval.valueOf(timeinterval));
|
||||
// log.info("retrieving quote for identifier:{} and time:{}",identifier,timeinterval);
|
||||
// quotaStorageStatusList.add(queryUsage.selectStorageQuota(identifier,TimeInterval.valueOf(timeinterval)));
|
||||
|
||||
}catch(Exception e){
|
||||
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST)
|
||||
.entity("Error : "+e.getMessage()).type(MediaType.TEXT_PLAIN).build());
|
||||
}
|
||||
return quotaStorageStatusList;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue