Search in sources :

Example 1 with Credential

use of nl.uva.cs.lobcder.resources.Credential in project lobcder by skoulouzis.

the class JDBCatalogue method insertOrUpdateStorageSites.

public void insertOrUpdateStorageSites(Collection<StorageSite> sites, Connection connection, Boolean includePrivate) throws SQLException {
    Collection<Credential> credentials = getCredentials(connection);
    Collection<StorageSite> existingSites = getStorageSites(connection, Boolean.FALSE, includePrivate);
    existingSites.addAll(getStorageSites(connection, Boolean.TRUE, includePrivate));
    Collection<String> updatedSites = new ArrayList<>();
    for (StorageSite s : sites) {
        long credentialID = -1;
        for (Credential c : credentials) {
            if (c.getStorageSiteUsername().equals(s.getCredential().getStorageSiteUsername()) && c.getStorageSitePassword().equals(s.getCredential().getStorageSitePassword())) {
                credentialID = c.getId();
                break;
            }
        }
        if (credentialID == -1) {
            try (PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO credential_table (username, " + "password) VALUES (?, ?)", Statement.RETURN_GENERATED_KEYS)) {
                preparedStatement.setString(1, s.getCredential().getStorageSiteUsername());
                preparedStatement.setString(2, s.getCredential().getStorageSitePassword());
                preparedStatement.executeUpdate();
                ResultSet rs = preparedStatement.getGeneratedKeys();
                rs.next();
                credentialID = rs.getLong(1);
                s.getCredential().setId(credentialID);
                credentials.add(s.getCredential());
            }
        }
        for (StorageSite es : existingSites) {
            if (es.getResourceURI().equals(s.getResourceURI())) {
                // Long id = es.getStorageSiteId();
                try (PreparedStatement preparedStatement = connection.prepareStatement("UPDATE storage_site_table SET " + "resourceUri = ?, " + "credentialRef = ?, " + "currentNum = ?, " + "currentSize = ?, " + "quotaNum = ?, " + "quotaSize = ?, " + "isCache = ?, " + "encrypt = ? " + "WHERE storageSiteId = ?")) {
                    preparedStatement.setString(1, s.getResourceURI());
                    preparedStatement.setLong(2, credentialID);
                    preparedStatement.setLong(3, s.getCurrentNum());
                    preparedStatement.setLong(4, s.getCurrentSize());
                    preparedStatement.setLong(5, s.getQuotaNum());
                    preparedStatement.setLong(6, s.getQuotaSize());
                    preparedStatement.setBoolean(7, s.isCache());
                    preparedStatement.setBoolean(8, s.isEncrypt());
                    preparedStatement.setLong(9, es.getStorageSiteId());
                    preparedStatement.executeUpdate();
                }
                updatedSites.add(es.getResourceURI());
            }
        }
        if (!updatedSites.contains(s.getResourceURI())) {
            try (PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO storage_site_table " + "(resourceUri, credentialRef, currentNum, " + "currentSize, quotaNum, quotaSize, isCache, extra, " + "encrypt) " + "VALUES (?, ?, ?, ?, ?, ?, ?, NULL, ?)", Statement.RETURN_GENERATED_KEYS)) {
                preparedStatement.setString(1, s.getResourceURI());
                preparedStatement.setLong(2, credentialID);
                preparedStatement.setLong(3, s.getCurrentNum());
                preparedStatement.setLong(4, s.getCurrentSize());
                preparedStatement.setLong(5, s.getQuotaNum());
                preparedStatement.setLong(6, s.getQuotaSize());
                preparedStatement.setBoolean(7, s.isCache());
                preparedStatement.setBoolean(8, s.isEncrypt());
                preparedStatement.executeUpdate();
                ResultSet rs = preparedStatement.getGeneratedKeys();
                rs.next();
                s.setStorageSiteId(rs.getLong(1));
                existingSites.add(s);
            }
        }
    }
}
Also used : Credential(nl.uva.cs.lobcder.resources.Credential) StorageSite(nl.uva.cs.lobcder.resources.StorageSite)

Example 2 with Credential

use of nl.uva.cs.lobcder.resources.Credential in project lobcder by skoulouzis.

the class RegisterSRMSites method initVFS.

private static void initVFS() throws VlException, MalformedURLException, NamingException, Exception {
    vfsClient = new VFSClient();
    VRSContext context = vfsClient.getVRSContext();
    BdiiService bdii = context.getBdiiService();
    srms = bdii.getSRMv22SAsforVO("biomed");
    // 
    debug("srms: " + context.getConfigManager().getBdiiHost());
    for (StorageArea inf : srms) {
        debug("srms: " + inf.getVOStorageLocation());
    }
    JDBCatalogue cat = new JDBCatalogue();
    String resourceURI = "";
    Credential credentials = new Credential();
// cat.registerStorageSite(resourceURI, credentials, -1, -1, -1, -1, null);
}
Also used : VRSContext(nl.uva.vlet.vrs.VRSContext) VFSClient(nl.uva.vlet.vfs.VFSClient) Credential(nl.uva.cs.lobcder.resources.Credential) JDBCatalogue(nl.uva.cs.lobcder.catalogue.JDBCatalogue) StorageArea(nl.uva.vlet.util.bdii.StorageArea) BdiiService(nl.uva.vlet.util.bdii.BdiiService)

Example 3 with Credential

use of nl.uva.cs.lobcder.resources.Credential in project lobcder by skoulouzis.

the class Assimilator method main.

public static void main(String[] args) throws SQLException, MalformedURLException, VlException, NoSuchAlgorithmException, Exception {
    try {
        importingOwner = "admin";
        List<StorageSite> sites = new ArrayList<>();
        Credential credential = new Credential();
        credential.setStorageSiteUsername("fake");
        credential.setStorageSitePassword("fake");
        // StorageSite ss1 = new StorageSite();
        // ss1.setCredential(credential);
        // ss1.setResourceURI("swift://somewhere:8443/auth/v1.0/uploadContainer/");
        // ss1.setCurrentNum(Long.valueOf("-1"));
        // ss1.setCurrentSize(Long.valueOf("-1"));
        // ss1.setEncrypt(false);
        // ss1.setQuotaNum(Long.valueOf("-1"));
        // ss1.setQuotaSize(Long.valueOf("-1"));
        // sites.add(ss1);
        // 
        // 
        // StorageSite ss2 = new StorageSite();
        // ss2.setCredential(credential);
        // ss2.setResourceURI("file:///" + System.getProperty("user.home") + "/Downloads");
        // ss2.setCurrentNum(Long.valueOf("-1"));
        // ss2.setCurrentSize(Long.valueOf("-1"));
        // ss2.setEncrypt(false);
        // ss2.setQuotaNum(Long.valueOf("-1"));
        // ss2.setQuotaSize(Long.valueOf("-1"));
        // sites.add(ss2);
        // StorageSite ss3 = new StorageSite();
        // ss3.setCredential(credential);
        // ss3.setResourceURI("file:///" + System.getProperty("user.home") + "/Downloads/lobcderUsageData");
        // //            ss3.setResourceURI("srm://tbn18.nikhef.nl:8446/dpm/nikhef.nl/home/biomed/lobcder");
        // ss3.setCurrentNum(Long.valueOf("-1"));
        // ss3.setCurrentSize(Long.valueOf("-1"));
        // ss3.setEncrypt(false);
        // ss3.setQuotaNum(Long.valueOf("-1"));
        // ss3.setQuotaSize(Long.valueOf("-1"));
        // sites.add(ss3);
        StorageSite ss4 = new StorageSite();
        ss4.setCredential(credential);
        ss4.setResourceURI("http://data.sdss3.org/sas/dr12/apogee/spectro/redux/r5/apo1m/calibration/56357/plots/");
        ss4.setCurrentNum(Long.valueOf("-1"));
        ss4.setCurrentSize(Long.valueOf("-1"));
        ss4.setEncrypt(false);
        ss4.setQuotaNum(Long.valueOf("-1"));
        ss4.setQuotaSize(Long.valueOf("-1"));
        ss4.setPrivateSite(false);
        ss4.setReadOnly(true);
        sites.add(ss4);
        Assimilator a = new Assimilator();
        a.assimilate(sites);
    } catch (Exception ex) {
        ex.printStackTrace();
        Logger.getLogger(Assimilator.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        VRS.exit();
        System.exit(0);
    }
}
Also used : Credential(nl.uva.cs.lobcder.resources.Credential) StorageSite(nl.uva.cs.lobcder.resources.StorageSite) ArrayList(java.util.ArrayList) MalformedURLException(java.net.MalformedURLException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) VlException(nl.uva.vlet.exception.VlException)

Example 4 with Credential

use of nl.uva.cs.lobcder.resources.Credential in project lobcder by skoulouzis.

the class StorageSitesService method set.

@Path("set/")
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public void set(JAXBElement<StorageSiteWrapperList> jbSites) throws SQLException {
    MyPrincipal mp = (MyPrincipal) request.getAttribute("myprincipal");
    if (mp.isAdmin()) {
        try (Connection connection = getCatalogue().getConnection()) {
            StorageSiteWrapperList sitesWL = jbSites.getValue();
            List<StorageSiteWrapper> sswl = sitesWL.getSites();
            if (sswl != null && sswl.size() > 0) {
                Collection<StorageSite> sites = new ArrayList<>();
                for (StorageSiteWrapper ssw : sswl) {
                    StorageSite site = new StorageSite();
                    Credential cred = new Credential();
                    cred.setStorageSitePassword(ssw.getCredential().getStorageSitePassword());
                    cred.setStorageSiteUsername(ssw.getCredential().getStorageSiteUsername());
                    site.setCredential(cred);
                    site.setCurrentNum(ssw.getCurrentNum());
                    site.setCurrentSize(ssw.getCurrentSize());
                    site.setResourceURI(ssw.getResourceURI());
                    site.setEncrypt(ssw.isEncrypt());
                    site.setCache(ssw.isCache());
                    site.setQuotaNum(ssw.getQuotaNum());
                    site.setQuotaSize(ssw.getQuotaSize());
                    sites.add(site);
                }
                getCatalogue().insertOrUpdateStorageSites(sites, connection);
                connection.commit();
            }
        }
    }
}
Also used : StorageSiteWrapper(nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper) StorageSiteWrapperList(nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapperList) MyPrincipal(nl.uva.cs.lobcder.auth.MyPrincipal) Credential(nl.uva.cs.lobcder.resources.Credential) StorageSite(nl.uva.cs.lobcder.resources.StorageSite) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 5 with Credential

use of nl.uva.cs.lobcder.resources.Credential in project lobcder by skoulouzis.

the class JDBCatalogue method insertOrUpdateStorageSites.

public void insertOrUpdateStorageSites(Collection<StorageSite> sites, Connection connection) throws SQLException {
    Collection<Credential> credentials = getCredentials(connection);
    Collection<StorageSite> existingSites = getStorageSites(connection, Boolean.FALSE);
    existingSites.addAll(getStorageSites(connection, Boolean.TRUE));
    Collection<String> updatedSites = new ArrayList<>();
    for (StorageSite s : sites) {
        long credentialID = -1;
        for (Credential c : credentials) {
            if (c.getStorageSiteUsername().equals(s.getCredential().getStorageSiteUsername()) && c.getStorageSitePassword().equals(s.getCredential().getStorageSitePassword())) {
                credentialID = c.getId();
                break;
            }
        }
        if (credentialID == -1) {
            try (PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO credential_table (username, " + "password) VALUES (?, ?)", Statement.RETURN_GENERATED_KEYS)) {
                preparedStatement.setString(1, s.getCredential().getStorageSiteUsername());
                preparedStatement.setString(2, s.getCredential().getStorageSitePassword());
                preparedStatement.executeUpdate();
                ResultSet rs = preparedStatement.getGeneratedKeys();
                rs.next();
                credentialID = rs.getLong(1);
                s.getCredential().setId(credentialID);
                credentials.add(s.getCredential());
            }
        }
        for (StorageSite es : existingSites) {
            if (es.getResourceURI().equals(s.getResourceURI())) {
                // Long id = es.getStorageSiteId();
                try (PreparedStatement preparedStatement = connection.prepareStatement("UPDATE storage_site_table SET " + "`resourceUri` = ?, " + "`credentialRef` = ?, " + "`currentNum` = ?, " + "`currentSize` = ?, " + "`quotaNum` = ?, " + "`quotaSize` = ?, " + "`isCache` = ?, " + "`encrypt` = ? " + "WHERE storageSiteId = ?;")) {
                    preparedStatement.setString(1, s.getResourceURI());
                    preparedStatement.setLong(2, credentialID);
                    preparedStatement.setLong(3, s.getCurrentNum());
                    preparedStatement.setLong(4, s.getCurrentSize());
                    preparedStatement.setLong(5, s.getQuotaNum());
                    preparedStatement.setLong(6, s.getQuotaSize());
                    preparedStatement.setBoolean(7, s.isCache());
                    preparedStatement.setBoolean(8, s.isEncrypt());
                    preparedStatement.setLong(9, es.getStorageSiteId());
                    preparedStatement.executeUpdate();
                }
                updatedSites.add(es.getResourceURI());
            }
        }
        if (!updatedSites.contains(s.getResourceURI())) {
            try (PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO storage_site_table " + "(resourceUri, credentialRef, currentNum, " + "currentSize, quotaNum, quotaSize, isCache, extra, " + "encrypt) " + "VALUES (?, ?, ?, ?, ?, ?, ?, NULL, ?)", Statement.RETURN_GENERATED_KEYS)) {
                preparedStatement.setString(1, s.getResourceURI());
                preparedStatement.setLong(2, credentialID);
                preparedStatement.setLong(3, s.getCurrentNum());
                preparedStatement.setLong(4, s.getCurrentSize());
                preparedStatement.setLong(5, s.getQuotaNum());
                preparedStatement.setLong(6, s.getQuotaSize());
                preparedStatement.setBoolean(7, s.isCache());
                preparedStatement.setBoolean(8, s.isEncrypt());
                preparedStatement.executeUpdate();
                ResultSet rs = preparedStatement.getGeneratedKeys();
                rs.next();
                s.setStorageSiteId(rs.getLong(1));
                existingSites.add(s);
            }
        }
    }
}
Also used : Credential(nl.uva.cs.lobcder.resources.Credential) StorageSite(nl.uva.cs.lobcder.resources.StorageSite)

Aggregations

Credential (nl.uva.cs.lobcder.resources.Credential)8 StorageSite (nl.uva.cs.lobcder.resources.StorageSite)6 ArrayList (java.util.ArrayList)2 MalformedURLException (java.net.MalformedURLException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 HashMap (java.util.HashMap)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 MyPrincipal (nl.uva.cs.lobcder.auth.MyPrincipal)1 JDBCatalogue (nl.uva.cs.lobcder.catalogue.JDBCatalogue)1 StorageSiteWrapper (nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapper)1 StorageSiteWrapperList (nl.uva.cs.lobcder.rest.wrappers.StorageSiteWrapperList)1 VlException (nl.uva.vlet.exception.VlException)1 BdiiService (nl.uva.vlet.util.bdii.BdiiService)1 StorageArea (nl.uva.vlet.util.bdii.StorageArea)1 VFSClient (nl.uva.vlet.vfs.VFSClient)1