Search in sources :

Example 6 with StorageSiteWrapper

use of nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper in project lobcder by skoulouzis.

the class Catalogue method getStorageSites.

private List<StorageSiteWrapper> getStorageSites(String id) throws URISyntaxException, UnknownHostException, SocketException, IOException {
    if (restClient == null) {
        restClient = Client.create(clientConfig);
        restClient.removeAllFilters();
        restClient.addFilter(new com.sun.jersey.api.client.filter.HTTPBasicAuthFilter("worker-", token));
        webResource = restClient.resource(restURL);
    }
    MultivaluedMap<String, String> params = new MultivaluedMapImpl();
    params.add("id", id);
    WebResource res = webResource.path("storage_sites").queryParams(params);
    StorageSiteWrapperList storageSiteList = res.accept(MediaType.APPLICATION_XML).get(new GenericType<StorageSiteWrapperList>() {
    });
    List<StorageSiteWrapper> ssites = removeUnreachableStorageSites(storageSiteList);
    for (StorageSiteWrapper ssw : ssites) {
        storageSiteCache.put(ssw.getStorageSiteId(), ssw);
    }
    return ssites;
}
Also used : StorageSiteWrapper(nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper) StorageSiteWrapperList(nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapperList) WebResource(com.sun.jersey.api.client.WebResource) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl)

Example 7 with StorageSiteWrapper

use of nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper in project lobcder by skoulouzis.

the class Catalogue method removeUnreachableStorageSites.

private List<StorageSiteWrapper> removeUnreachableStorageSites(StorageSiteWrapperList sites) throws URISyntaxException, UnknownHostException, SocketException, IOException {
    List<StorageSiteWrapper> ssites = sites.getSites();
    if (ssites != null) {
        List<StorageSiteWrapper> removeIt = new ArrayList<>();
        for (StorageSiteWrapper p : sites.getSites()) {
            URI uri = new URI(p.getResourceURI());
            String pdriHost = uri.getHost();
            String pdriScheme = uri.getScheme();
            if (pdriHost == null || pdriHost.equals("localhost") || pdriHost.startsWith("127.0.")) {
                removeIt.add(p);
            } else if (pdriScheme.equals("file") && !Catalogue.isPDRIOnWorker(new URI(p.getResourceURI()))) {
                removeIt.add(p);
            }
        }
        if (!removeIt.isEmpty()) {
            ssites.removeAll(removeIt);
            if (ssites.isEmpty()) {
                Logger.getLogger(Catalogue.class.getName()).log(Level.SEVERE, "PDRIS from master is either empty or contains unreachable files");
                throw new IOException("PDRIS from master is either empty or contains unreachable files");
            }
        }
    }
    return ssites;
}
Also used : StorageSiteWrapper(nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URI(java.net.URI)

Example 8 with StorageSiteWrapper

use of nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper in project lobcder by skoulouzis.

the class Catalogue method replicate.

boolean replicate(Pair<File, String> p) throws IOException {
    boolean result = true;
    PDRIDescr sourceDescr = createPdriDescr(p.getLeft());
    PDRI sourcePdri = PDRIFactory.getFactory().createInstance(sourceDescr);
    String[] sites = p.getRight().split("-");
    Long fileUID = Long.valueOf(sites[0]);
    Long pdriGroupId = Long.valueOf(sites[1]);
    List<PDRIDescr> destinationDescrList = new ArrayList<>();
    for (int i = 2; i < sites.length; i++) {
        try {
            StorageSiteWrapper ss = storageSiteCache.get(Long.valueOf(sites[i]));
            if (ss == null) {
                getStorageSites(String.valueOf(Long.valueOf(sites[i])));
                ss = storageSiteCache.get(Long.valueOf(sites[i]));
            }
            BigInteger pdriKey = nl.uva.cs.lobcder.util.DesEncrypter.generateKey();
            PDRIDescr destinationDescr = new PDRIDescr(sourceDescr.getName(), ss.getStorageSiteId(), ss.getResourceURI(), ss.getCredential().getStorageSiteUsername(), ss.getCredential().getStorageSitePassword(), ss.isEncrypt(), pdriKey, pdriGroupId, null, ss.isCache());
            PDRI destinationPdri = PDRIFactory.getFactory().createInstance(destinationDescr);
            destinationPdri.replicate(sourcePdri);
            result = destinationPdri.exists(destinationPdri.getFileName());
            long srcLen = sourcePdri.getLength();
            if (result == false || destinationPdri.getLength() != srcLen) {
                result = false;
            }
            destinationDescrList.add(destinationDescr);
        } catch (Exception e) {
            result = false;
        } catch (Throwable e) {
            result = false;
        }
    }
    result = updateMaster(destinationDescrList, fileUID);
    return result;
}
Also used : PDRIDescr(nl.uva.cs.lobcder.resources.PDRIDescr) ArrayList(java.util.ArrayList) VPDRI(nl.uva.cs.lobcder.resources.VPDRI) PDRI(nl.uva.cs.lobcder.resources.PDRI) URISyntaxException(java.net.URISyntaxException) JAXBException(javax.xml.bind.JAXBException) SocketException(java.net.SocketException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) UnknownHostException(java.net.UnknownHostException) StorageSiteWrapper(nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper) BigInteger(java.math.BigInteger)

Aggregations

StorageSiteWrapper (nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper)8 ArrayList (java.util.ArrayList)6 StorageSiteWrapperList (nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapperList)4 Connection (java.sql.Connection)3 MyPrincipal (nl.uva.cs.lobcder.auth.MyPrincipal)3 StorageSite (nl.uva.cs.lobcder.resources.StorageSite)3 IOException (java.io.IOException)2 Consumes (javax.ws.rs.Consumes)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 CredentialWrapped (nl.uva.cs.lobcder.rest.wrappers.CredentialWrapped)2 WebResource (com.sun.jersey.api.client.WebResource)1 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)1 BigInteger (java.math.BigInteger)1 SocketException (java.net.SocketException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 CertificateException (java.security.cert.CertificateException)1 SQLException (java.sql.SQLException)1