Fabio Sinibaldi 2018-02-28 10:41:49 +00:00
parent e2ae6180c8
commit 7d8149048d
6 changed files with 84 additions and 19 deletions

View File

@ -169,7 +169,7 @@ public class REST {
log.info("Received GET request at {} , descriptor option is {} ",pathString,getDescriptor);
long volume=0l;
boolean success=true;
String path=pathString;
String path=destinationID+":"+subPath;
String mimeType="N/A";
try{
if(getDescriptor) return Response.ok(persistence.getDescriptor(destinationID, subPath), MediaType.APPLICATION_JSON_TYPE).build();
@ -202,7 +202,7 @@ public class REST {
long volume=0l;
boolean success=true;
String path=pathString;
String path=destinationID+":"+subPath;
String mimeType="N/A";
try{

View File

@ -163,7 +163,10 @@ public abstract class AbstractTicketHandler {
if(Files.exists(destination.toPath()))
currentAccountingDetails.setUpdatedFile(true);
currentAccountingDetails.setVolume(tempFile.length());
currentAccountingDetails.setUri(destination.toURI().toString());
currentAccountingDetails.setUri(ticket.getDestinationSettings().getPersistenceId()+":"+ticket.getDestinationSettings().getSubFolder()+"/"+ticket.getDestinationFileName());
currentAccountingDetails.setMimeType(new MimetypesFileTypeMap().getContentType(tempFile));
Files.copy(tempFile.toPath(), destination.toPath(),StandardCopyOption.REPLACE_EXISTING);

View File

@ -1,6 +1,7 @@
package org.gcube.data.transfer.service.transfers.engine.impl;
import java.net.URI;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
@ -35,25 +36,42 @@ public class AccountingManagerImpl implements AccountingManager {
@Override
public String createNewRecord(){
try {
StorageUsageRecord newer=initRecord();
return records.put(newer.getId(),newer).getId();
log.debug("Created record : {} ",newer);
records.put(newer.getId(),newer);
return newer.getId();
}catch(Throwable t) {
log.warn("Unable to register new record ",t);
return "fake";
}
}
private StorageUsageRecord getById(String recordId) {
return records.get(recordId);
try{
return records.get(recordId);
}catch(Throwable t) {
log.warn("Unable to locate Accountind record with id {} ",recordId,t);
return null;
}
}
@Override
public void account(String toAccountRecordId) {
StorageUsageRecord record=getById(toAccountRecordId);
StorageUsageRecord record=null;
try{
record=getById(toAccountRecordId);
AccountingPersistence persistence = AccountingPersistenceFactory.getPersistence();
persistence.account(record);
}catch(Exception e) {
}catch(Throwable e) {
log.warn("Unable to account record {}.",record,e);
}
records.remove(toAccountRecordId);
try{
records.remove(toAccountRecordId);
}catch(Throwable t) {
log.warn("Unable to remove record by id {} ",toAccountRecordId,t);
}
}
@ -62,7 +80,7 @@ public class AccountingManagerImpl implements AccountingManager {
public void setSuccessful(String id, boolean succesfull) {
try {
getById(id).setOperationResult(succesfull?OperationResult.SUCCESS:OperationResult.FAILED);
} catch (InvalidValueException e) {
} catch (Throwable e) {
log.warn("Unable to update record {}.",getById(id),e);
}
}
@ -72,7 +90,7 @@ public class AccountingManagerImpl implements AccountingManager {
public void setRead(String id) {
try {
getById(id).setOperationType(OperationType.READ);
} catch (InvalidValueException e) {
} catch (Throwable e) {
log.warn("Unable to update record {}.",getById(id),e);
}
}
@ -82,7 +100,7 @@ public class AccountingManagerImpl implements AccountingManager {
public void setCreate(String id) {
try {
getById(id).setOperationType(OperationType.CREATE);
} catch (InvalidValueException e) {
} catch (Throwable e) {
log.warn("Unable to update record {}.",getById(id),e);
}
}
@ -92,7 +110,7 @@ public class AccountingManagerImpl implements AccountingManager {
public void setDelete(String id) {
try {
getById(id).setOperationType(OperationType.DELETE);
} catch (InvalidValueException e) {
} catch (Throwable e) {
log.warn("Unable to update record {}.",getById(id),e);
}
}
@ -102,7 +120,7 @@ public class AccountingManagerImpl implements AccountingManager {
public void setUpdate(String id) {
try {
getById(id).setOperationType(OperationType.UPDATE);
} catch (InvalidValueException e) {
} catch (Throwable e) {
log.warn("Unable to update record {}.",getById(id),e);
}
}
@ -112,7 +130,7 @@ public class AccountingManagerImpl implements AccountingManager {
public void setResourceURI(String id, String uri) {
try {
getById(id).setResourceURI(new URI(uri));
} catch (Exception e) {
} catch (Throwable e) {
log.warn("Unable to update record {}.",getById(id),e);
}
}
@ -147,7 +165,7 @@ public class AccountingManagerImpl implements AccountingManager {
String currentUser=TokenUtils.getCurrentUser();
record.setConsumerId(currentUser);
record.setResourceOwner(currentUser);
record.setResourceScope(record.getScope());
ApplicationContext context=ContextProvider.get();
ContainerConfiguration configuration=context.container().configuration();
@ -156,8 +174,8 @@ public class AccountingManagerImpl implements AccountingManager {
record.setProviderURI(new URI(hostName));
record.setDataType(AbstractStorageUsageRecord.DataType.OTHER);
}catch(Exception e) {
log.warn("Unable to create account record, returning empty one.. ",e);
}catch(Throwable t) {
log.warn("Unable to create account record, returning empty one : {} ",record,t);
}

View File

@ -1,8 +1,11 @@
package org.gcube.data.transfer.service.transfers.engine.impl;
import java.util.Properties;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
@ -16,6 +19,7 @@ import org.gcube.data.transfer.service.transfers.engine.PersistenceProvider;
import org.gcube.data.transfer.service.transfers.engine.PluginManager;
import org.gcube.data.transfer.service.transfers.engine.RequestManager;
import org.gcube.data.transfer.service.transfers.engine.TicketManager;
import org.gcube.smartgears.ContextProvider;
import lombok.extern.slf4j.Slf4j;
@ -32,8 +36,27 @@ public class RequestManagerImpl implements RequestManager{
@Inject
public RequestManagerImpl(TicketManager ticketManager,PersistenceProvider persistenceProvider) {
executor=Executors.newCachedThreadPool();
public RequestManagerImpl(TicketManager ticketManager,PersistenceProvider persistenceProvider) {
log.info("Checking pool configuration..");
int coreSize=5;
int maximumSize=10;
long maximumIdleTime=60000;
try {
Properties props=new Properties();
props.load(ContextProvider.get().application().getResourceAsStream("config.properties"));
coreSize=Integer.parseInt(props.getProperty("transfers.poolCoreSize"));
maximumSize=Integer.parseInt(props.getProperty("transfers.poolMaximumSize"));
maximumIdleTime=Long.parseLong(props.getProperty("transfers.threadMaxIdleTimeMs"));
}catch(Throwable t) {
log.warn("****************************************************************************");
log.warn("Unable to read configuration, reverting to default pool values ");
log.warn("Core size {} , maximum size {} , maximum idle time {}",coreSize,maximumSize,maximumIdleTime);
log.warn("Error was ",t);
}
executor=new ThreadPoolExecutor(coreSize, maximumSize, maximumIdleTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
this.persistenceProvider=persistenceProvider;
this.pluginManager=PluginManager.get();
this.ticketManager=ticketManager;

View File

@ -0,0 +1,5 @@
#TRANSFER POOL CONFIGURATION
transfers.poolMaximumSize=40
transfers.poolCoreSize=5
transfers.threadMaxIdleTimeMs=60000

View File

@ -0,0 +1,16 @@
package org.gcube.data.transfer.service;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.data.transfer.service.transfers.engine.AccountingManager;
public class Accountingtests {
public static void main(String[] args) {
SecurityTokenProvider.instance.set("feda0617-cd9d-4841-b6f0-e047da5d32ed-98187548");
AccountingManager manager=AccountingManager.get();
String id=manager.createNewRecord();
manager.setSuccessful(id, true);
System.out.println("DONE");
}
}