Search in sources :

Example 1 with DataRequest

use of es.bsc.compss.nio.dataRequest.DataRequest in project compss by bsc-wdc.

the class NIOWorkerNode method sendData.

@Override
public void sendData(LogicalData ld, DataLocation source, DataLocation target, LogicalData tgtData, Transferable reason, EventListener listener) {
    if (target.getHosts().contains(Comm.getAppHost())) {
        // Order petition directly
        if (tgtData != null) {
            MultiURI u = ld.alreadyAvailable(Comm.getAppHost());
            if (u != null) {
                // Already present at the master
                reason.setDataTarget(u.getPath());
                listener.notifyEnd(null);
                return;
            }
        }
        Copy c = new DeferredCopy(ld, null, target, tgtData, reason, listener);
        Data d = new Data(ld);
        if (source != null) {
            for (MultiURI uri : source.getURIs()) {
                try {
                    NIOURI nURI = (NIOURI) uri.getInternalURI(NIOAdaptor.ID);
                    if (nURI != null) {
                        d.getSources().add(nURI);
                    }
                } catch (UnstartedNodeException une) {
                // Ignore internal URI
                }
            }
        }
        String path = target.getURIInHost(Comm.getAppHost()).getPath();
        c.setFinalTarget(path);
        ld.startCopy(c, c.getTargetLoc());
        DataRequest dr = new MasterDataRequest(c, reason.getType(), d, path);
        commManager.addTransferRequest(dr);
        commManager.requestTransfers();
    } else {
        // Request to any other
        orderCopy(new DeferredCopy(ld, source, target, tgtData, reason, listener));
    }
}
Also used : DeferredCopy(es.bsc.compss.types.data.operation.copy.DeferredCopy) MultiURI(es.bsc.compss.types.uri.MultiURI) DeferredCopy(es.bsc.compss.types.data.operation.copy.DeferredCopy) Copy(es.bsc.compss.types.data.operation.copy.Copy) StorageCopy(es.bsc.compss.types.data.operation.copy.StorageCopy) UnstartedNodeException(es.bsc.compss.exceptions.UnstartedNodeException) LogicalData(es.bsc.compss.types.data.LogicalData) Data(es.bsc.compss.nio.commands.Data) MasterDataRequest(es.bsc.compss.nio.dataRequest.MasterDataRequest) DataRequest(es.bsc.compss.nio.dataRequest.DataRequest) MasterDataRequest(es.bsc.compss.nio.dataRequest.MasterDataRequest) NIOURI(es.bsc.compss.nio.NIOURI)

Example 2 with DataRequest

use of es.bsc.compss.nio.dataRequest.DataRequest in project compss by bsc-wdc.

the class NIOWorker method askForTransfer.

private void askForTransfer(boolean askTransfer, NIOParam param, int index, TransferringTask tt) {
    // Request the transfer if needed
    if (askTransfer) {
        WORKER_LOGGER.info("- Parameter " + index + "(" + (String) param.getValue() + ") does not exist, requesting data transfer");
        DataRequest dr = new WorkerDataRequest(tt, param.getType(), param.getData(), (String) param.getValue());
        addTransferRequest(dr);
    } else {
        // If no transfer, decrease the parameter counter
        // (we already have it)
        WORKER_LOGGER.info("- Parameter " + index + "(" + (String) param.getValue() + ") already exists.");
        tt.decreaseParams();
    }
}
Also used : WorkerDataRequest(es.bsc.compss.nio.dataRequest.WorkerDataRequest) WorkerDataRequest(es.bsc.compss.nio.dataRequest.WorkerDataRequest) DataRequest(es.bsc.compss.nio.dataRequest.DataRequest)

Example 3 with DataRequest

use of es.bsc.compss.nio.dataRequest.DataRequest in project compss by bsc-wdc.

the class NIOAgent method receivedData.

/**
 * Received Data
 *
 * @param c
 * @param t
 */
public void receivedData(Connection c, Transfer t) {
    String dataId = ongoingTransfers.remove(c);
    if (dataId == null) {
        // execution
        return;
    }
    releaseReceiveSlot();
    List<DataRequest> requests = dataToRequests.remove(dataId);
    Map<String, List<DataRequest>> byTarget = new HashMap<>();
    for (DataRequest req : requests) {
        List<DataRequest> sameTarget = byTarget.get(req.getTarget());
        if (sameTarget == null) {
            sameTarget = new LinkedList<DataRequest>();
            byTarget.put(req.getTarget(), sameTarget);
        }
        sameTarget.add(req);
    }
    if (NIOTracer.isActivated()) {
        int tag = abs(dataId.hashCode());
        NIOTracer.emitDataTransferEvent(dataId);
        NIOTracer.emitCommEvent(false, connection2Partner.get(c), tag, t.getSize());
        connection2Partner.remove(c);
    }
    if (byTarget.size() == 1) {
        String targetName = requests.get(0).getTarget();
        receivedValue(t.getDestination(), targetName, t.getObject(), requests);
    } else {
        if (t.isFile()) {
            receivedValue(t.getDestination(), t.getFileName(), t.getObject(), byTarget.remove(t.getFileName()));
        } else {
            receivedValue(t.getDestination(), dataId, t.getObject(), byTarget.remove(dataId));
        }
        for (Entry<String, List<DataRequest>> entry : byTarget.entrySet()) {
            String targetName = entry.getKey();
            List<DataRequest> reqs = entry.getValue();
            try {
                if (t.isFile()) {
                    Files.copy((new File(t.getFileName())).toPath(), (new File(targetName)).toPath());
                    receivedValue(t.getDestination(), targetName, t.getObject(), byTarget.remove(targetName));
                } else {
                    Object o = Serializer.deserialize(t.getArray());
                    receivedValue(t.getDestination(), targetName, o, reqs);
                }
            } catch (IOException | ClassNotFoundException e) {
                LOGGER.warn("Can not replicate received Data", e);
            }
        }
    }
    requestTransfers();
    // Check if shutdown and ready
    if (finish == true && !hasPendingTransfers()) {
        shutdown(closingConnection);
    }
}
Also used : HashMap(java.util.HashMap) DataRequest(es.bsc.compss.nio.dataRequest.DataRequest) IOException(java.io.IOException) LinkedList(java.util.LinkedList) List(java.util.List) File(java.io.File)

Example 4 with DataRequest

use of es.bsc.compss.nio.dataRequest.DataRequest in project compss by bsc-wdc.

the class NIOAdaptor method handleRequestedDataNotAvailableError.

@Override
public void handleRequestedDataNotAvailableError(List<DataRequest> failedRequests, String dataId) {
    for (DataRequest dr : failedRequests) {
        MasterDataRequest mdr = (MasterDataRequest) dr;
        Copy c = (Copy) mdr.getOperation();
        c.getSourceData().finishedCopy(c);
        // Notify the copy has failed
        c.end(DataOperation.OpEndState.OP_FAILED);
    }
}
Also used : Copy(es.bsc.compss.types.data.operation.copy.Copy) MasterDataRequest(es.bsc.compss.nio.dataRequest.MasterDataRequest) DataRequest(es.bsc.compss.nio.dataRequest.DataRequest) MasterDataRequest(es.bsc.compss.nio.dataRequest.MasterDataRequest)

Example 5 with DataRequest

use of es.bsc.compss.nio.dataRequest.DataRequest in project compss by bsc-wdc.

the class NIOAgent method requestTransfers.

/**
 * Check if receive slots available
 */
public void requestTransfers() {
    DataRequest dr = null;
    synchronized (pendingRequests) {
        if (!pendingRequests.isEmpty() && tryAcquireReceiveSlot()) {
            dr = pendingRequests.remove();
        }
    }
    while (dr != null) {
        Data source = dr.getSource();
        NIOURI uri = source.getFirstURI();
        if (NIOTracer.isActivated()) {
            NIOTracer.emitDataTransferEvent(source.getName());
        }
        NIONode nn = uri.getHost();
        if (nn.getIp() == null) {
            nn = masterNode;
        }
        Connection c = null;
        try {
            c = TM.startConnection(nn);
            LOGGER.debug("Connection " + c.hashCode() + " will be used to acquire data " + dr.getTarget() + " stored in " + nn + " with name " + dr.getSource().getName());
            Data remoteData = new Data(source.getName(), uri);
            CommandDataDemand cdd = new CommandDataDemand(this, remoteData, tracingID);
            ongoingTransfers.put(c, dr.getSource().getName());
            c.sendCommand(cdd);
            if (NIOTracer.isActivated()) {
                c.receive();
            }
            if (dr.getType() == DataType.FILE_T) {
                c.receiveDataFile(dr.getTarget());
            } else {
                c.receiveDataObject();
            }
        } catch (Exception e) {
            e.printStackTrace(System.err);
        } finally {
            if (c != null) {
                c.finishConnection();
            }
        }
        synchronized (pendingRequests) {
            if (!pendingRequests.isEmpty() && tryAcquireReceiveSlot()) {
                dr = pendingRequests.remove();
            } else {
                dr = null;
            }
        }
        if (NIOTracer.isActivated()) {
            NIOTracer.emitDataTransferEvent(NIOTracer.TRANSFER_END);
        }
    }
}
Also used : NIONode(es.bsc.comm.nio.NIONode) CommandDataDemand(es.bsc.compss.nio.commands.CommandDataDemand) Connection(es.bsc.comm.Connection) DataRequest(es.bsc.compss.nio.dataRequest.DataRequest) Data(es.bsc.compss.nio.commands.Data) SerializedObjectException(es.bsc.compss.nio.exceptions.SerializedObjectException) IOException(java.io.IOException)

Aggregations

DataRequest (es.bsc.compss.nio.dataRequest.DataRequest)9 MasterDataRequest (es.bsc.compss.nio.dataRequest.MasterDataRequest)4 WorkerDataRequest (es.bsc.compss.nio.dataRequest.WorkerDataRequest)3 Copy (es.bsc.compss.types.data.operation.copy.Copy)3 IOException (java.io.IOException)3 Data (es.bsc.compss.nio.commands.Data)2 LogicalData (es.bsc.compss.types.data.LogicalData)2 File (java.io.File)2 Connection (es.bsc.comm.Connection)1 NIONode (es.bsc.comm.nio.NIONode)1 UnstartedNodeException (es.bsc.compss.exceptions.UnstartedNodeException)1 NIOURI (es.bsc.compss.nio.NIOURI)1 CommandDataDemand (es.bsc.compss.nio.commands.CommandDataDemand)1 SerializedObjectException (es.bsc.compss.nio.exceptions.SerializedObjectException)1 DataLocation (es.bsc.compss.types.data.location.DataLocation)1 DeferredCopy (es.bsc.compss.types.data.operation.copy.DeferredCopy)1 StorageCopy (es.bsc.compss.types.data.operation.copy.StorageCopy)1 MultiURI (es.bsc.compss.types.uri.MultiURI)1 FileOutputStream (java.io.FileOutputStream)1 HashMap (java.util.HashMap)1