Search in sources :

Example 1 with TapClient

use of org.opencadc.tap.TapClient in project caom2db by opencadc.

the class InventoryArtifactStore method init.

private void init() {
    Subject subject = AuthenticationUtil.getCurrentSubject();
    AuthMethod authMethod = AuthenticationUtil.getAuthMethodFromCredentials(subject);
    URI securityMethod = Standards.getSecurityMethod(authMethod);
    if (storageInventoryTapURL == null) {
        try {
            TapClient tapClient = new TapClient<>(queryServiceResourceID);
            storageInventoryTapURL = tapClient.getSyncURL(securityMethod);
        } catch (Throwable t) {
            String message = "Failed to initialize Storage-Inventory TAP URL";
            throw new RuntimeException(message, t);
        }
    }
}
Also used : TapClient(org.opencadc.tap.TapClient) URI(java.net.URI) Subject(javax.security.auth.Subject) AuthMethod(ca.nrc.cadc.auth.AuthMethod)

Example 2 with TapClient

use of org.opencadc.tap.TapClient in project caom2db by opencadc.

the class ArtifactValidator method getLogicalMetadata.

private TreeSet<ArtifactMetadata> getLogicalMetadata() throws Exception {
    TreeSet<ArtifactMetadata> result = new TreeSet<>(ArtifactMetadata.getComparator());
    if (StringUtil.hasText(source)) {
        // use database <server.database.schema>
        // HarvestSkipURI table is not supported in 'diff' mode, i.e. reportOnly = true
        this.supportSkipURITable = !reportOnly;
        long t1 = System.currentTimeMillis();
        List<ObservationState> states = observationDAO.getObservationList(collection, null, null, null);
        long t2 = System.currentTimeMillis();
        long dt = t2 - t1;
        log.info("get-state-list: size=" + states.size() + " in " + dt + " ms");
        int depth = 3;
        ListIterator<ObservationState> iter = states.listIterator();
        t1 = System.currentTimeMillis();
        while (iter.hasNext()) {
            ObservationState s = iter.next();
            // GC
            iter.remove();
            ObservationResponse resp = observationDAO.getObservationResponse(s, depth);
            if (resp == null) {
                log.error("Null response from Observation DAO, ObservationURI: " + s.getURI().toString() + ", depth: " + depth);
            } else if (resp.observation == null) {
                log.error("Observation is null, ObservationURI: " + s.getURI().toString() + ", depth: " + depth);
            } else {
                for (Plane plane : resp.observation.getPlanes()) {
                    for (Artifact artifact : plane.getArtifacts()) {
                        String observationID = s.getURI().getObservationID();
                        result.add(getMetadata(observationID, artifact, plane.dataRelease, plane.metaRelease));
                    }
                }
            }
        }
        log.info("Finished logical metadata query in " + (System.currentTimeMillis() - t1) + " ms");
    } else {
        this.supportSkipURITable = false;
        if (caomTapResourceID != null) {
            // source is a TAP resource ID
            AuthMethod authMethod = AuthenticationUtil.getAuthMethodFromCredentials(AuthenticationUtil.getCurrentSubject());
            TapClient tapClient = new TapClient(caomTapResourceID);
            try {
                this.caomTapURL = tapClient.getSyncURL(authMethod);
            } catch (ResourceNotFoundException ex) {
                if (ex.getMessage().contains("with password")) {
                    throw new ResourceNotFoundException("TAP service for " + caomTapResourceID + " does not support password authentication.", ex);
                }
            }
        }
        // source is a TAP service URL or a TAP resource ID
        String adql = "select distinct(a.uri), a.contentChecksum, a.contentLength, a.contentType, o.observationID, " + "a.productType, a.releaseType, p.dataRelease, p.metaRelease " + "from caom2.Artifact a " + "join caom2.Plane p on a.planeID = p.planeID " + "join caom2.Observation o on p.obsID = o.obsID " + "where o.collection='" + collection + "'";
        log.debug("logical query: " + adql);
        long start = System.currentTimeMillis();
        result = query(caomTapURL, adql);
        log.info("Finished caom2 query in " + (System.currentTimeMillis() - start) + " ms");
    }
    return result;
}
Also used : Plane(ca.nrc.cadc.caom2.Plane) Artifact(ca.nrc.cadc.caom2.Artifact) AuthMethod(ca.nrc.cadc.auth.AuthMethod) TreeSet(java.util.TreeSet) ObservationResponse(ca.nrc.cadc.caom2.ObservationResponse) TapClient(org.opencadc.tap.TapClient) ObservationState(ca.nrc.cadc.caom2.ObservationState) ResourceNotFoundException(ca.nrc.cadc.net.ResourceNotFoundException) ArtifactMetadata(ca.nrc.cadc.caom2.artifact.ArtifactMetadata)

Aggregations

AuthMethod (ca.nrc.cadc.auth.AuthMethod)2 TapClient (org.opencadc.tap.TapClient)2 Artifact (ca.nrc.cadc.caom2.Artifact)1 ObservationResponse (ca.nrc.cadc.caom2.ObservationResponse)1 ObservationState (ca.nrc.cadc.caom2.ObservationState)1 Plane (ca.nrc.cadc.caom2.Plane)1 ArtifactMetadata (ca.nrc.cadc.caom2.artifact.ArtifactMetadata)1 ResourceNotFoundException (ca.nrc.cadc.net.ResourceNotFoundException)1 URI (java.net.URI)1 TreeSet (java.util.TreeSet)1 Subject (javax.security.auth.Subject)1