Search in sources :

Example 1 with Environment

use of ca.nrc.cadc.caom2.Environment in project java-notebooks by googleapis.

the class ITNotebookServiceClientTest method testGetEnvironment.

@Test
public void testGetEnvironment() {
    GetEnvironmentRequest environmentRequest = GetEnvironmentRequest.newBuilder().setName(ENVIRONMENT_NAME).build();
    Environment expectedEnvironmentResponse = client.getEnvironment(environmentRequest);
    assertEquals(expectedEnvironmentResponse.getName(), expectedEnvironmentResponse.getName());
    assertEquals(expectedEnvironmentResponse.getContainerImage(), expectedEnvironmentResponse.getContainerImage());
}
Also used : Environment(com.google.cloud.notebooks.v1beta1.Environment) GetEnvironmentRequest(com.google.cloud.notebooks.v1beta1.GetEnvironmentRequest) Test(org.junit.Test)

Example 2 with Environment

use of ca.nrc.cadc.caom2.Environment in project java-notebooks by googleapis.

the class ITNotebookServiceClientTest method testListEnvironment.

@Test
public void testListEnvironment() {
    ListEnvironmentsRequest request = ListEnvironmentsRequest.newBuilder().setParent(PARENT).build();
    for (Environment element : client.listEnvironments(request).iterateAll()) {
        if (element.getName().equals(ENVIRONMENT_ID)) {
            assertEquals(expectedEnvironmentResponse.getName(), element.getName());
            assertEquals(expectedEnvironmentResponse.getContainerImage(), element.getContainerImage());
        }
    }
}
Also used : ListEnvironmentsRequest(com.google.cloud.notebooks.v1beta1.ListEnvironmentsRequest) Environment(com.google.cloud.notebooks.v1beta1.Environment) Test(org.junit.Test)

Example 3 with Environment

use of ca.nrc.cadc.caom2.Environment in project caom2db by opencadc.

the class ObservationValidator method doit.

private Progress doit() {
    Progress ret = new Progress();
    long t = System.currentTimeMillis();
    long timeState = -1;
    long timeQuery = -1;
    long timeTransaction = -1;
    try {
        // hint
        System.gc();
        t = System.currentTimeMillis();
        timeState = System.currentTimeMillis() - t;
        t = System.currentTimeMillis();
        log.info("getObservationList: " + src.getIdentifier());
        List<ObservationState> tmpSrcState = null;
        if (srcObservationDAO != null) {
            tmpSrcState = srcObservationDAO.getObservationList(src.getCollection(), null, null, null);
        } else if (srcObservationService != null) {
            tmpSrcState = srcObservationService.getObservationList(src.getCollection(), null, null, null);
        } else {
            throw new RuntimeException("BUG: both srcObservationDAO and srcObservationService are null");
        }
        log.info("found: " + tmpSrcState.size());
        Set<ObservationState> srcState = new TreeSet<>(compStateUri);
        srcState.addAll(tmpSrcState);
        // GC
        tmpSrcState = null;
        log.info("source set: " + srcState.size());
        log.info("getObservationList: " + dest.getIdentifier());
        List<ObservationState> tmpDstState = destObservationDAO.getObservationList(dest.getCollection(), null, null, null);
        log.info("found: " + tmpDstState.size());
        Set<ObservationState> dstState = new TreeSet<>(compStateUri);
        dstState.addAll(tmpDstState);
        // GC
        tmpDstState = null;
        log.info("destination set: " + dstState.size());
        Set<ObservationStateError> errlist = calculateErroneousObservationStates(srcState, dstState);
        log.info("discrepancies found: " + errlist.size());
        timeQuery = System.currentTimeMillis() - t;
        t = System.currentTimeMillis();
        List<SkippedWrapperURI<ObservationStateError>> entityListSrc = wrap(errlist);
        ret.found = srcState.size();
        ListIterator<SkippedWrapperURI<ObservationStateError>> iter = entityListSrc.listIterator();
        while (iter.hasNext()) {
            SkippedWrapperURI<ObservationStateError> ow = iter.next();
            ObservationStateError o = ow.entity;
            // allow garbage collection during loop
            iter.remove();
            String skipMsg = null;
            try {
                if (!dryrun) {
                    if (o != null) {
                        skipMsg = o.toString();
                        try {
                            log.debug("starting HarvestSkipURI transaction");
                            boolean putSkip = true;
                            HarvestSkipURI skip = harvestSkip.get(source, cname, o.getObs().getURI().getURI());
                            Date tryAfter = o.getObs().maxLastModified;
                            if (skip == null) {
                                skip = new HarvestSkipURI(source, cname, o.getObs().getURI().getURI(), tryAfter, skipMsg);
                                ret.added++;
                            } else {
                                // avoid lastModified update for no change
                                putSkip = false;
                                ret.known++;
                            }
                            if (destObservationDAO.getTransactionManager().isOpen()) {
                                throw new RuntimeException("BUG: found open trasnaction at start of next observation");
                            }
                            log.debug("starting transaction");
                            destObservationDAO.getTransactionManager().startTransaction();
                            // track the fail
                            if (putSkip) {
                                log.info("put: " + skip);
                                harvestSkip.put(skip);
                            } else {
                                log.info("known: " + skip);
                            }
                        } catch (Throwable oops) {
                            log.warn("failed to insert HarvestSkipURI", oops);
                            destObservationDAO.getTransactionManager().rollbackTransaction();
                            log.warn("rollback HarvestSkipURI: OK");
                        }
                    }
                    log.debug("committing transaction");
                    destObservationDAO.getTransactionManager().commitTransaction();
                    log.debug("commit: OK");
                }
                ret.mismatch++;
            } catch (Throwable oops) {
                String str = oops.toString();
                if (oops instanceof Error) {
                    log.error("FATAL - probably installation or environment", oops);
                } else if (oops instanceof NullPointerException) {
                    log.error("BUG", oops);
                } else if (oops instanceof BadSqlGrammarException) {
                    log.error("BUG", oops);
                    BadSqlGrammarException bad = (BadSqlGrammarException) oops;
                    SQLException sex1 = bad.getSQLException();
                    if (sex1 != null) {
                        log.error("CAUSE", sex1);
                        SQLException sex2 = sex1.getNextException();
                        log.error("NEXT CAUSE", sex2);
                    }
                } else if (oops instanceof DataAccessResourceFailureException) {
                    log.error("SEVERE PROBLEM - probably out of space in database", oops);
                } else if (oops instanceof DataIntegrityViolationException && str.contains("duplicate key value violates unique constraint \"i_observationuri\"")) {
                    log.error("CONTENT PROBLEM - duplicate observation: " + " " + o.getObs().getURI().getURI().toASCIIString());
                } else if (oops instanceof UncategorizedSQLException) {
                    if (str.contains("spherepoly_from_array")) {
                        log.error("UNDETECTED illegal polygon: " + o.getObs().getURI().getURI());
                    } else {
                        log.error("unexpected exception", oops);
                    }
                } else if (oops instanceof IllegalArgumentException && str.contains("CaomValidator") && str.contains("keywords")) {
                    log.error("CONTENT PROBLEM - invalid keywords: " + " " + o.getObs().getURI().getURI().toASCIIString());
                } else {
                    log.error("unexpected exception", oops);
                }
            }
        }
    } finally {
        timeTransaction = System.currentTimeMillis() - t;
        log.debug("time to get HarvestState: " + timeState + "ms");
        log.debug("time to run ObservationListQuery: " + timeQuery + "ms");
        log.debug("time to run transactions: " + timeTransaction + "ms");
    }
    return ret;
}
Also used : BadSqlGrammarException(org.springframework.jdbc.BadSqlGrammarException) UncategorizedSQLException(org.springframework.jdbc.UncategorizedSQLException) SQLException(java.sql.SQLException) UncategorizedSQLException(org.springframework.jdbc.UncategorizedSQLException) TreeSet(java.util.TreeSet) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) HarvestSkipURI(ca.nrc.cadc.caom2.harvester.state.HarvestSkipURI) Date(java.util.Date) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) ObservationState(ca.nrc.cadc.caom2.ObservationState)

Example 4 with Environment

use of ca.nrc.cadc.caom2.Environment in project java-notebooks by googleapis.

the class ITNotebookServiceClientTest method setUp.

@BeforeClass
public static void setUp() throws IOException, ExecutionException, InterruptedException {
    // Create Test Notebook Instance
    client = NotebookServiceClient.create();
    ContainerImage containerImage = ContainerImage.newBuilder().setRepository(FieldBehavior.OPTIONAL.name()).build();
    Environment environment = Environment.newBuilder().setName(ENVIRONMENT_NAME).setContainerImage(containerImage).build();
    CreateEnvironmentRequest environmentRequest = CreateEnvironmentRequest.newBuilder().setParent(PARENT).setEnvironmentId(ENVIRONMENT_ID).setEnvironment(environment).build();
    expectedEnvironmentResponse = client.createEnvironmentAsync(environmentRequest).get();
    Instance notebookInstance = Instance.newBuilder().setContainerImage(containerImage).setMachineType(MACHINE_TYPE_A).build();
    CreateInstanceRequest instanceRequest = CreateInstanceRequest.newBuilder().setParent(PARENT).setInstanceId(NOTEBOOK_INSTANCE_ID).setInstance(notebookInstance).build();
    expectedNotebookInstance = client.createInstanceAsync(instanceRequest).get();
}
Also used : CreateEnvironmentRequest(com.google.cloud.notebooks.v1beta1.CreateEnvironmentRequest) Instance(com.google.cloud.notebooks.v1beta1.Instance) ContainerImage(com.google.cloud.notebooks.v1beta1.ContainerImage) Environment(com.google.cloud.notebooks.v1beta1.Environment) CreateInstanceRequest(com.google.cloud.notebooks.v1beta1.CreateInstanceRequest) BeforeClass(org.junit.BeforeClass)

Example 5 with Environment

use of ca.nrc.cadc.caom2.Environment in project caom2db by opencadc.

the class AbstractObservationDAOTest method getTestObservation.

private Observation getTestObservation(boolean full, int depth, boolean comp, boolean sci) throws Exception {
    Observation o;
    if (comp) {
        DerivedObservation obs = new DerivedObservation("TEST", "SimpleBar", new Algorithm("doit"));
        if (full) {
            obs.getMembers().add(new ObservationURI("TEST", "simple1"));
            obs.getMembers().add(new ObservationURI("TEST", "simple2"));
            obs.getMembers().add(new ObservationURI("TEST", "simple3"));
        }
        o = obs;
    } else
        o = new SimpleObservation("TEST", "SimpleBar");
    if (full) {
        o.metaProducer = URI.create("test:observation/roundrip-1.0");
        if (sci)
            o.intent = ObservationIntentType.SCIENCE;
        else {
            o.intent = ObservationIntentType.CALIBRATION;
            o.type = "flat";
        }
        o.sequenceNumber = new Integer(123);
        o.metaRelease = TEST_DATE;
        o.proposal = new Proposal("MyFirstProposal");
        o.proposal.getKeywords().addAll(TEST_KEYWORDS);
        o.proposal.pi = "little old me";
        o.proposal.title = "My Little Pony";
        o.proposal.project = "Project 51";
        o.target = new Target("Pony 51");
        o.target.targetID = URI.create("naif:1701");
        o.target.type = TargetType.OBJECT;
        o.target.getKeywords().addAll(TEST_KEYWORDS);
        o.target.standard = Boolean.TRUE;
        o.target.redshift = new Double(0.0);
        o.target.moving = Boolean.FALSE;
        o.targetPosition = new TargetPosition("FK5", new Point(1.0, 2.0));
        if (sci)
            o.targetPosition.equinox = 2000.0;
        o.requirements = new Requirements(Status.FAIL);
        o.telescope = new Telescope("BothEyes");
        o.telescope.getKeywords().addAll(TEST_KEYWORDS);
        o.telescope.geoLocationX = 100.0;
        o.telescope.geoLocationY = 200.0;
        o.telescope.geoLocationZ = 300.0;
        o.instrument = new Instrument("test-instrument");
        o.instrument.getKeywords().addAll(TEST_KEYWORDS);
        o.environment = new Environment();
        o.environment.seeing = 0.08;
        o.environment.photometric = Boolean.TRUE;
        o.getMetaReadGroups().add(URI.create("ivo://example.net/gms?GroupA"));
        o.getMetaReadGroups().add(URI.create("ivo://example.net/gms?GroupB"));
    }
    if (depth == 1)
        return o;
    o.getPlanes().add(getTestPlane(full, "thing1", depth, true));
    o.getPlanes().add(getTestPlane(full, "thing2", depth, false));
    Assert.assertEquals(2, o.getPlanes().size());
    return o;
}
Also used : ObservationURI(ca.nrc.cadc.caom2.ObservationURI) Telescope(ca.nrc.cadc.caom2.Telescope) Point(ca.nrc.cadc.caom2.types.Point) Algorithm(ca.nrc.cadc.caom2.Algorithm) TargetPosition(ca.nrc.cadc.caom2.TargetPosition) Requirements(ca.nrc.cadc.caom2.Requirements) DerivedObservation(ca.nrc.cadc.caom2.DerivedObservation) Target(ca.nrc.cadc.caom2.Target) SimpleObservation(ca.nrc.cadc.caom2.SimpleObservation) DerivedObservation(ca.nrc.cadc.caom2.DerivedObservation) Observation(ca.nrc.cadc.caom2.Observation) DeletedObservation(ca.nrc.cadc.caom2.DeletedObservation) SimpleObservation(ca.nrc.cadc.caom2.SimpleObservation) Instrument(ca.nrc.cadc.caom2.Instrument) Environment(ca.nrc.cadc.caom2.Environment) Proposal(ca.nrc.cadc.caom2.Proposal)

Aggregations

Environment (com.google.cloud.notebooks.v1beta1.Environment)3 Observation (ca.nrc.cadc.caom2.Observation)2 ObservationState (ca.nrc.cadc.caom2.ObservationState)2 ObservationURI (ca.nrc.cadc.caom2.ObservationURI)2 HarvestSkipURI (ca.nrc.cadc.caom2.harvester.state.HarvestSkipURI)2 SQLException (java.sql.SQLException)2 Date (java.util.Date)2 Test (org.junit.Test)2 DataAccessResourceFailureException (org.springframework.dao.DataAccessResourceFailureException)2 BadSqlGrammarException (org.springframework.jdbc.BadSqlGrammarException)2 Algorithm (ca.nrc.cadc.caom2.Algorithm)1 Artifact (ca.nrc.cadc.caom2.Artifact)1 DeletedObservation (ca.nrc.cadc.caom2.DeletedObservation)1 DerivedObservation (ca.nrc.cadc.caom2.DerivedObservation)1 Environment (ca.nrc.cadc.caom2.Environment)1 Instrument (ca.nrc.cadc.caom2.Instrument)1 ObservationResponse (ca.nrc.cadc.caom2.ObservationResponse)1 Plane (ca.nrc.cadc.caom2.Plane)1 Proposal (ca.nrc.cadc.caom2.Proposal)1 Requirements (ca.nrc.cadc.caom2.Requirements)1