bug fix on resourceURI and ProviderURI
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/content-management/storage-manager-trigger@119561 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
2dda9867be
commit
8519e74c9f
|
@ -2,6 +2,7 @@ package org.gcube.contentmanager.storageserver.accounting;
|
|||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Date;
|
||||
|
||||
import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord.OperationType;
|
||||
|
@ -9,6 +10,7 @@ import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
|
|||
import org.gcube.accounting.exception.InvalidValueException;
|
||||
import org.gcube.accounting.persistence.AccountingPersistence;
|
||||
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
|
||||
import org.gcube.contentmanager.storageserver.parse.utils.DateUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -16,6 +18,7 @@ import org.slf4j.LoggerFactory;
|
|||
final Logger logger = LoggerFactory.getLogger(ReportAccountingImpl.class);
|
||||
public StorageUsageRecord sur;
|
||||
public AccountingPersistence accountingPersistence;
|
||||
private String providerUri;
|
||||
// public ResourceAccounting raFactory;
|
||||
|
||||
|
||||
|
@ -42,7 +45,11 @@ import org.slf4j.LoggerFactory;
|
|||
sur.setDataType(StorageUsageRecord.DataType.STORAGE);
|
||||
sur.setOperationResult(OperationResult.SUCCESS);
|
||||
if(consumerId!=null) sur.setConsumerId(consumerId);
|
||||
if(resourceScope !=null) sur.setResourceScope(resourceScope);
|
||||
if(resourceScope !=null){
|
||||
sur.setResourceScope(resourceScope);
|
||||
//it is extracted from resourceScope
|
||||
sur=setProviderUri(sur, resourceScope);
|
||||
}
|
||||
if(owner != null) sur.setResourceOwner(owner);
|
||||
if (operation != null){
|
||||
OperationType accountingOperation=convertOperation(operation);
|
||||
|
@ -50,8 +57,7 @@ import org.slf4j.LoggerFactory;
|
|||
sur.setOperationType(accountingOperation);
|
||||
}
|
||||
if(size!= null) sur.setDataVolume(Long.parseLong(size));
|
||||
sur.setResourceURI(new URI("NOT_PROVIDED"));
|
||||
sur.setProviderURI(new URI("NOT_PROVIDED"));
|
||||
|
||||
} catch (InvalidValueException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
|
@ -63,12 +69,26 @@ import org.slf4j.LoggerFactory;
|
|||
return sur;
|
||||
}
|
||||
|
||||
private StorageUsageRecord setProviderUri(StorageUsageRecord sur, String resourceScope) throws InvalidValueException, URISyntaxException {
|
||||
logger.debug("retrieve root scope from resourceScope "+resourceScope);
|
||||
String rootScope= resourceScope.substring(1);
|
||||
logger.debug("rootScope extrapolated is: "+rootScope);
|
||||
if(rootScope.indexOf("/") != -1){
|
||||
rootScope=rootScope.substring(0, rootScope.indexOf("/"));
|
||||
logger.debug("removed sub scopes. rootScope: "+rootScope);
|
||||
}
|
||||
providerUri="data."+rootScope+".org";
|
||||
logger.debug("set provider uri: "+providerUri);
|
||||
sur.setProviderURI(new URI(providerUri));
|
||||
return sur;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public StorageUsageRecord setSpecificProperties(StorageUsageRecord sur, String filePath,
|
||||
String dataType, String callerIP, String id) {
|
||||
logger.trace("set accounting properties: remotePath: "+filePath+" dataType "+dataType+" callerIP "+callerIP);
|
||||
logger.trace("set accounting properties: remotePath: "+filePath+" dataType "+dataType+" callerIP "+callerIP+" resoruceURI "+id);
|
||||
if(sur==null) sur = new StorageUsageRecord();
|
||||
try {
|
||||
if(filePath != null){
|
||||
|
@ -78,7 +98,11 @@ import org.slf4j.LoggerFactory;
|
|||
sur.setResourceProperty("callerIP", callerIP);
|
||||
}
|
||||
if(id != null){
|
||||
sur.setResourceProperty("id", id);
|
||||
try {
|
||||
sur.setResourceURI(new URI(id));
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (InvalidValueException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -117,7 +141,10 @@ import org.slf4j.LoggerFactory;
|
|||
"\n\t file "+record.getResourceProperty("remotePath")+
|
||||
"\n\t size "+record.getDataVolume()+ //("dataVolume")+
|
||||
"\n\t caller "+record.getResourceProperty("callerIP")+
|
||||
"\n\t id "+record.getResourceProperty("id")+
|
||||
"\n\t id "+record.getId()+
|
||||
"\n\t resourceURI "+record.getResourceURI()+
|
||||
"\n\t providerURI "+record.getProviderURI()+
|
||||
"\n\t Now "+DateUtils.now("dd MM yyyy 'at' hh:mm:ss z")+
|
||||
"\n\t operation "+record.getOperationType());//("operationType"));
|
||||
}
|
||||
|
||||
|
|
|
@ -82,17 +82,19 @@ public class UserAccountingConsumer extends Thread{
|
|||
OpLogRemoteObject record=retrieveObjectFields(obj);
|
||||
// set object dimension
|
||||
|
||||
logger.debug("[recordCheck] operation: "+op+" name: "+record.getName()+" type: "+record.getType()+" path: "+record.getFilename()+" length: "+record.getLength()+" owner: "+record.getOwner()+ " lastOperation "+record.getLastOperation()+" lastUser: "+record.getLastUser()+" lastAccess: "+record.getLastAccess());
|
||||
if(((record.getLength() >0) && (((record.getFilename() !=null) && (record.getFilename().contains("/"))) || (record.getLinkCount() > 0)))){
|
||||
logger.debug("[recordCheck] operation: "+op+" name: "+record.getName()+" type: "+record.getType()+" path: "+record.getFilename()+" dir Path: "+record.getDir()+" length: "+record.getLength()+" owner: "+record.getOwner()+ " lastOperation "+record.getLastOperation()+" lastUser: "+record.getLastUser()+" lastAccess: "+record.getLastAccess());
|
||||
if(((record.getLength() >0) && (((record.getFilename() !=null) && (record.getFilename().length()>0) && (record.getDir().length()>0)&& (record.getDir().contains("/"))) || (record.getLinkCount() > 0)))){
|
||||
//convert from byte to kb
|
||||
record.setLength(record.getLength()/1024);
|
||||
// check scope
|
||||
String scope=null;
|
||||
if((record.getFilename()!=null)&& (record.getFilename().contains("/")))
|
||||
scope=retrieveScopeFromRemoteFilePath(record.getFilename());
|
||||
else{
|
||||
String pathString=(String)obj.get("onScope");
|
||||
logger.debug("pathString value: "+pathString);
|
||||
if((record.getDir()!=null)&& (record.getDir().contains("/"))){
|
||||
scope=retrieveScopeFromRemoteFilePath(record.getDir());
|
||||
logger.debug("scope retrieved: "+scope);
|
||||
}else{
|
||||
// field added on storage manager library for retrieve scope. Used only if it is a link delete
|
||||
String pathString=(String)obj.get("onScope");
|
||||
scope=retrieveScopeFromRemoteFilePath(pathString);
|
||||
}
|
||||
boolean validScope=ValidationUtils.validationScope(scope);
|
||||
|
@ -192,6 +194,7 @@ public class UserAccountingConsumer extends Thread{
|
|||
record.setName( (String) obj.get("name"));
|
||||
record.setOwner((String) obj.get("owner"));
|
||||
record.setCreationTime((String) obj.get("creationTime"));
|
||||
record.setDir((String) obj.get("dir"));
|
||||
if(obj.get("lastAccess") != null) record.setLastAccess((String)obj.get("lastAccess"));
|
||||
if(obj.get("callerIP") != null) record.setCallerIp((String)obj.get("callerIP"));
|
||||
if(obj.get("lastOperation") != null) record.setLastOperation((String)obj.get("lastOperation"));
|
||||
|
|
|
@ -14,6 +14,7 @@ public class OpLogRemoteObject {
|
|||
private String delete;
|
||||
private String callerIp;
|
||||
private String id;
|
||||
private String dir;
|
||||
private long length;
|
||||
|
||||
|
||||
|
@ -99,6 +100,12 @@ public class OpLogRemoteObject {
|
|||
this.length=length;
|
||||
|
||||
}
|
||||
public String getDir() {
|
||||
return dir;
|
||||
}
|
||||
public void setDir(String dir) {
|
||||
this.dir = dir;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package org.gcube.contentmanager.storageserver.parse.utils;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.text.SimpleDateFormat;
|
||||
/**
|
||||
* Calculates the current Date
|
||||
* @author Roberto Cirillo (ISTI - CNR)
|
||||
*
|
||||
*/
|
||||
public class DateUtils {
|
||||
|
||||
|
||||
/**
|
||||
* usage: DateUtils.now("dd MMMMM yyyy")
|
||||
*
|
||||
* @param dateFormat "dd MMMMM yyyy"
|
||||
* @return the converted string
|
||||
*/
|
||||
public static String now(String dateFormat) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
|
||||
return sdf.format(cal.getTime());
|
||||
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@ public class ValidationUtils {
|
|||
private static final Logger logger = LoggerFactory.getLogger(ValidationUtils.class);
|
||||
|
||||
public static boolean validationScope(String scope){
|
||||
logger.debug("scope Validation for scope "+scope);
|
||||
ScopeBean scopeBean=new ScopeBean(scope);
|
||||
if((scopeBean.is(Type.VRE)))
|
||||
scope=scopeBean.enclosingScope().toString();
|
||||
|
|
Loading…
Reference in New Issue