package org.gcube.data.transfer.library.transferers; import lombok.extern.slf4j.Slf4j; import org.gcube.data.transfer.library.caches.CapabilitiesCache; import org.gcube.data.transfer.library.faults.HostingNodeNotFoundException; import org.gcube.data.transfer.library.faults.ServiceNotFoundException; import org.gcube.data.transfer.library.faults.UnreachableNodeException; import org.gcube.data.transfer.library.utils.Utils; import org.gcube.data.transfer.model.ServiceConstants; import org.gcube.data.transfer.model.TransferCapabilities; @Slf4j public class TransfererBuilder { private static final int timeout=10*1000; public static Transferer getTransfererByHost(String host) throws UnreachableNodeException, ServiceNotFoundException{ log.debug("Get transferer by Host "+host); if(!Utils.pingURL(host, timeout)) throw new UnreachableNodeException("No response from host in "+timeout); if(!Utils.pingURL(host+"REST-API/"+ServiceConstants.APPLICATION_PATH, timeout)) throw new ServiceNotFoundException("No DT Service found @ "+host+"REST-API/"+ServiceConstants.APPLICATION_PATH); log.debug("Host is ok, getting targetCapabilities"); TransferCapabilities cap=CapabilitiesCache.getInstance().getObject(host); return new HTTPTransferer(cap); } public static Transferer getTransfererByhostingNodeId(String hostId) throws HostingNodeNotFoundException, UnreachableNodeException, ServiceNotFoundException{ String hostname=retrieveHostnameByNodeId(hostId); return getTransfererByHost(hostname); } private static String retrieveHostnameByNodeId(String nodeId)throws HostingNodeNotFoundException{ return null; } }