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());
}
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());
}
}
}
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;
}
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();
}
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;
}
Aggregations