git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/data-transfer/data-transfer-service/2.0@164604 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e2ae6180c8
commit
7d8149048d
|
@ -169,7 +169,7 @@ public class REST {
|
||||||
log.info("Received GET request at {} , descriptor option is {} ",pathString,getDescriptor);
|
log.info("Received GET request at {} , descriptor option is {} ",pathString,getDescriptor);
|
||||||
long volume=0l;
|
long volume=0l;
|
||||||
boolean success=true;
|
boolean success=true;
|
||||||
String path=pathString;
|
String path=destinationID+":"+subPath;
|
||||||
String mimeType="N/A";
|
String mimeType="N/A";
|
||||||
try{
|
try{
|
||||||
if(getDescriptor) return Response.ok(persistence.getDescriptor(destinationID, subPath), MediaType.APPLICATION_JSON_TYPE).build();
|
if(getDescriptor) return Response.ok(persistence.getDescriptor(destinationID, subPath), MediaType.APPLICATION_JSON_TYPE).build();
|
||||||
|
@ -202,7 +202,7 @@ public class REST {
|
||||||
|
|
||||||
long volume=0l;
|
long volume=0l;
|
||||||
boolean success=true;
|
boolean success=true;
|
||||||
String path=pathString;
|
String path=destinationID+":"+subPath;
|
||||||
String mimeType="N/A";
|
String mimeType="N/A";
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
|
@ -163,7 +163,10 @@ public abstract class AbstractTicketHandler {
|
||||||
if(Files.exists(destination.toPath()))
|
if(Files.exists(destination.toPath()))
|
||||||
currentAccountingDetails.setUpdatedFile(true);
|
currentAccountingDetails.setUpdatedFile(true);
|
||||||
currentAccountingDetails.setVolume(tempFile.length());
|
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));
|
currentAccountingDetails.setMimeType(new MimetypesFileTypeMap().getContentType(tempFile));
|
||||||
|
|
||||||
Files.copy(tempFile.toPath(), destination.toPath(),StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(tempFile.toPath(), destination.toPath(),StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.gcube.data.transfer.service.transfers.engine.impl;
|
package org.gcube.data.transfer.service.transfers.engine.impl;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
|
import org.gcube.accounting.datamodel.UsageRecord.OperationResult;
|
||||||
|
@ -35,25 +36,42 @@ public class AccountingManagerImpl implements AccountingManager {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String createNewRecord(){
|
public String createNewRecord(){
|
||||||
|
try {
|
||||||
StorageUsageRecord newer=initRecord();
|
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) {
|
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
|
@Override
|
||||||
public void account(String toAccountRecordId) {
|
public void account(String toAccountRecordId) {
|
||||||
StorageUsageRecord record=getById(toAccountRecordId);
|
StorageUsageRecord record=null;
|
||||||
try{
|
try{
|
||||||
|
record=getById(toAccountRecordId);
|
||||||
AccountingPersistence persistence = AccountingPersistenceFactory.getPersistence();
|
AccountingPersistence persistence = AccountingPersistenceFactory.getPersistence();
|
||||||
persistence.account(record);
|
persistence.account(record);
|
||||||
}catch(Exception e) {
|
}catch(Throwable e) {
|
||||||
log.warn("Unable to account record {}.",record,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) {
|
public void setSuccessful(String id, boolean succesfull) {
|
||||||
try {
|
try {
|
||||||
getById(id).setOperationResult(succesfull?OperationResult.SUCCESS:OperationResult.FAILED);
|
getById(id).setOperationResult(succesfull?OperationResult.SUCCESS:OperationResult.FAILED);
|
||||||
} catch (InvalidValueException e) {
|
} catch (Throwable e) {
|
||||||
log.warn("Unable to update record {}.",getById(id),e);
|
log.warn("Unable to update record {}.",getById(id),e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +90,7 @@ public class AccountingManagerImpl implements AccountingManager {
|
||||||
public void setRead(String id) {
|
public void setRead(String id) {
|
||||||
try {
|
try {
|
||||||
getById(id).setOperationType(OperationType.READ);
|
getById(id).setOperationType(OperationType.READ);
|
||||||
} catch (InvalidValueException e) {
|
} catch (Throwable e) {
|
||||||
log.warn("Unable to update record {}.",getById(id),e);
|
log.warn("Unable to update record {}.",getById(id),e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +100,7 @@ public class AccountingManagerImpl implements AccountingManager {
|
||||||
public void setCreate(String id) {
|
public void setCreate(String id) {
|
||||||
try {
|
try {
|
||||||
getById(id).setOperationType(OperationType.CREATE);
|
getById(id).setOperationType(OperationType.CREATE);
|
||||||
} catch (InvalidValueException e) {
|
} catch (Throwable e) {
|
||||||
log.warn("Unable to update record {}.",getById(id),e);
|
log.warn("Unable to update record {}.",getById(id),e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +110,7 @@ public class AccountingManagerImpl implements AccountingManager {
|
||||||
public void setDelete(String id) {
|
public void setDelete(String id) {
|
||||||
try {
|
try {
|
||||||
getById(id).setOperationType(OperationType.DELETE);
|
getById(id).setOperationType(OperationType.DELETE);
|
||||||
} catch (InvalidValueException e) {
|
} catch (Throwable e) {
|
||||||
log.warn("Unable to update record {}.",getById(id),e);
|
log.warn("Unable to update record {}.",getById(id),e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +120,7 @@ public class AccountingManagerImpl implements AccountingManager {
|
||||||
public void setUpdate(String id) {
|
public void setUpdate(String id) {
|
||||||
try {
|
try {
|
||||||
getById(id).setOperationType(OperationType.UPDATE);
|
getById(id).setOperationType(OperationType.UPDATE);
|
||||||
} catch (InvalidValueException e) {
|
} catch (Throwable e) {
|
||||||
log.warn("Unable to update record {}.",getById(id),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) {
|
public void setResourceURI(String id, String uri) {
|
||||||
try {
|
try {
|
||||||
getById(id).setResourceURI(new URI(uri));
|
getById(id).setResourceURI(new URI(uri));
|
||||||
} catch (Exception e) {
|
} catch (Throwable e) {
|
||||||
log.warn("Unable to update record {}.",getById(id),e);
|
log.warn("Unable to update record {}.",getById(id),e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,7 +165,7 @@ public class AccountingManagerImpl implements AccountingManager {
|
||||||
String currentUser=TokenUtils.getCurrentUser();
|
String currentUser=TokenUtils.getCurrentUser();
|
||||||
record.setConsumerId(currentUser);
|
record.setConsumerId(currentUser);
|
||||||
record.setResourceOwner(currentUser);
|
record.setResourceOwner(currentUser);
|
||||||
|
record.setResourceScope(record.getScope());
|
||||||
ApplicationContext context=ContextProvider.get();
|
ApplicationContext context=ContextProvider.get();
|
||||||
ContainerConfiguration configuration=context.container().configuration();
|
ContainerConfiguration configuration=context.container().configuration();
|
||||||
|
|
||||||
|
@ -156,8 +174,8 @@ public class AccountingManagerImpl implements AccountingManager {
|
||||||
|
|
||||||
record.setProviderURI(new URI(hostName));
|
record.setProviderURI(new URI(hostName));
|
||||||
record.setDataType(AbstractStorageUsageRecord.DataType.OTHER);
|
record.setDataType(AbstractStorageUsageRecord.DataType.OTHER);
|
||||||
}catch(Exception e) {
|
}catch(Throwable t) {
|
||||||
log.warn("Unable to create account record, returning empty one.. ",e);
|
log.warn("Unable to create account record, returning empty one : {} ",record,t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package org.gcube.data.transfer.service.transfers.engine.impl;
|
package org.gcube.data.transfer.service.transfers.engine.impl;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
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.PluginManager;
|
||||||
import org.gcube.data.transfer.service.transfers.engine.RequestManager;
|
import org.gcube.data.transfer.service.transfers.engine.RequestManager;
|
||||||
import org.gcube.data.transfer.service.transfers.engine.TicketManager;
|
import org.gcube.data.transfer.service.transfers.engine.TicketManager;
|
||||||
|
import org.gcube.smartgears.ContextProvider;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@ -32,8 +36,27 @@ public class RequestManagerImpl implements RequestManager{
|
||||||
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public RequestManagerImpl(TicketManager ticketManager,PersistenceProvider persistenceProvider) {
|
public RequestManagerImpl(TicketManager ticketManager,PersistenceProvider persistenceProvider) {
|
||||||
executor=Executors.newCachedThreadPool();
|
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.persistenceProvider=persistenceProvider;
|
||||||
this.pluginManager=PluginManager.get();
|
this.pluginManager=PluginManager.get();
|
||||||
this.ticketManager=ticketManager;
|
this.ticketManager=ticketManager;
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
#TRANSFER POOL CONFIGURATION
|
||||||
|
transfers.poolMaximumSize=40
|
||||||
|
transfers.poolCoreSize=5
|
||||||
|
transfers.threadMaxIdleTimeMs=60000
|
||||||
|
|
|
@ -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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue