org.jenkinsci.plugins.docker.commons.fingerprint.DockerFingerprints Java Examples
The following examples show how to use
org.jenkinsci.plugins.docker.commons.fingerprint.DockerFingerprints.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FromFingerprintStepTest.java From docker-workflow-plugin with MIT License | 6 votes |
private void assertBuild(final String projectName, final String pipelineCode, final String fromImage) throws Exception { story.addStep(new Statement() { @Override public void evaluate() throws Throwable { assumeDocker(); WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, projectName); p.setDefinition(new CpsFlowDefinition(pipelineCode, true)); WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0)); DockerClient client = new DockerClient(new LocalLauncher(StreamTaskListener.NULL), null, null); String ancestorImageId = client.inspect(new EnvVars(), fromImage, ".Id"); story.j.assertLogContains(ancestorImageId.replaceFirst("^sha256:", "").substring(0, 12), b); Fingerprint f = DockerFingerprints.of(ancestorImageId); assertNotNull(f); DockerDescendantFingerprintFacet descendantFacet = f.getFacet(DockerDescendantFingerprintFacet.class); assertNotNull(descendantFacet); } }); }
Example #2
Source File: ContainerRecordUtils.java From yet-another-docker-plugin with MIT License | 6 votes |
public static void attachFacet(Run<?, ?> run, TaskListener listener) { final Executor executor = run.getExecutor(); if (executor == null) { return; } final Computer owner = executor.getOwner(); DockerComputer dockerComputer; if (owner instanceof DockerComputer) { dockerComputer = (DockerComputer) owner; try { DockerFingerprints.addRunFacet( createRecordFor(dockerComputer), run ); } catch (IOException | ParseException e) { listener.error("Can't add Docker fingerprint to run."); LOG.error("Can't add fingerprint to run {}", run, e); } } }
Example #3
Source File: DockerTraceabilityHelper.java From docker-traceability-plugin with MIT License | 6 votes |
/** * Retrieves the last {@link InspectImageResponse} for the specified image. * @param imageId Image Id * @return Last available report. Null if there is no data available * (or if an internal exception happens) */ public static @CheckForNull InspectImageResponse getLastInspectImageResponse(@Nonnull String imageId) { try { final Fingerprint fp = DockerFingerprints.of(imageId); if (fp != null) { final DockerInspectImageFacet facet = FingerprintsHelper.getFacet(fp, DockerInspectImageFacet.class); if (facet != null) { return facet.getData(); } } return null; } catch (IOException ex) { LOGGER.log(Level.WARNING, "Cannot retrieve deployment reports for imageId="+imageId, ex); return null; } }
Example #4
Source File: FingerprintTestUtil.java From docker-traceability-plugin with MIT License | 6 votes |
/** * A stub method, which emulates the submission of the image reference * from the web interface * @param req Incoming request * @param rsp Response * @param imageId image id * @param jobName job name, to which the facet should be attached * @throws IOException Request processing error * @throws ServletException Servlet error */ public static void doTestSubmitBuildRef(StaplerRequest req, StaplerResponse rsp, @QueryParameter(required = true) String imageId, @QueryParameter(required = true) String jobName) throws IOException, ServletException { final Jenkins j = Jenkins.getInstance(); if (j == null) { throw new IOException("Jenkins instance is not active"); } j.checkPermission(Jenkins.ADMINISTER); final AbstractProject item = j.getItem(jobName, j, AbstractProject.class); final Run latest = item != null ? item.getLastBuild() : null; if (latest == null) { throw new IOException("Cannot find a project or run to modify"); } DockerFingerprints.addFromFacet(null,imageId, latest); rsp.sendRedirect2(j.getRootUrl()); }
Example #5
Source File: DockerTraceabilityReportListenerImplTest.java From docker-traceability-plugin with MIT License | 6 votes |
/** * Checks the resolution of imageId from previously saved data. * @throws Exception test failure */ @Bug(28752) public void submitReportWithoutImageReference() throws Exception { DockerTraceabilityPluginTest.configure(new DockerTraceabilityPluginConfiguration(true, true)); final String imageId = FingerprintTestUtil.generateDockerId("1"); final Event event1 = new DockerEvent("run", imageId, "host", 12345).toDockerEvent(); final Event event2 = new DockerEvent("die", imageId, "host", 12346).toDockerEvent(); final InspectContainerResponse containerInfo = JSONSamples.inspectContainerData_emptyImage. readObject(InspectContainerResponse.class); DockerTraceabilityReport r1 = new DockerTraceabilityReport(event1, null, containerInfo, imageId, null, null, new LinkedList<String>(), null); DockerTraceabilityReport r2 = new DockerTraceabilityReport(event2, null, containerInfo, null, null, null, new LinkedList<String>(), null); // Spawn two reports DockerTraceabilityReportListener.fire(r1); DockerTraceabilityReportListener.fire(r2); // Retrieve final DockerDeploymentFacet facet = DockerFingerprints.getFacet(containerInfo.getId(), DockerDeploymentFacet.class); assertNotNull(facet); assertEquals(imageId, facet.getImageId()); assertEquals("Expected both reports to be saved in the fingerprint", 2, facet.getDeploymentRecords().size()); }
Example #6
Source File: DockerTraceabilityRootActionTest.java From docker-traceability-plugin with MIT License | 6 votes |
/** * Checks that the existence {@link DockerDeploymentRefFacet}. * @param containerId Container ID * @param imageId image ID * @return Facet (if validation passes) * @throws IOException test failure * @throws AssertionError Validation failure */ public DockerDeploymentRefFacet assertExistsDeploymentRefFacet (@Nonnull String containerId, @Nonnull String imageId) throws IOException { final Fingerprint imageFP = DockerFingerprints.of(imageId); assertNotNull(imageFP); final DockerDeploymentRefFacet containerRefFacet = FingerprintsHelper.getFacet(imageFP, DockerDeploymentRefFacet.class); assertNotNull(containerRefFacet); assertEquals(1, containerRefFacet.getContainerIds().size()); for (String containerRefId : containerRefFacet.getContainerIds()) { assertNotNull(containerRefFacet.getLastStatus(containerRefId)); } assertEquals(containerId, containerRefFacet.getContainerIds().toArray()[0]); return containerRefFacet; }
Example #7
Source File: RunFingerprintStep.java From docker-workflow-plugin with MIT License | 5 votes |
@SuppressWarnings("SynchronizeOnNonFinalField") // run is quasi-final @Override protected Void run() throws Exception { DockerClient client = new DockerClient(launcher, node, step.toolName); DockerFingerprints.addRunFacet(client.getContainerRecord(env, step.containerId), run); String image = client.inspect(env, step.containerId, ".Config.Image"); if (image != null) { ImageAction.add(image, run); } return null; }
Example #8
Source File: DockerDeploymentFacet.java From docker-traceability-plugin with MIT License | 5 votes |
public static @Nonnull DockerDeploymentFacet getOrCreate(@Nonnull Fingerprint fingerprint) throws IOException { DockerDeploymentFacet res = DockerFingerprints.getFacet(fingerprint, DockerDeploymentFacet.class); if (res != null) { return res; } // Create new one DockerDeploymentFacet facet = new DockerDeploymentFacet(fingerprint); fingerprint.getFacets().add(facet); fingerprint.save(); return facet; }
Example #9
Source File: DockerTraceabilityRootActionTest.java From docker-traceability-plugin with MIT License | 5 votes |
@Test @Bug(28656) public void createFingerPrintsOnDemand() throws Exception { // Read data from resources String inspectData = JSONSamples.inspectContainerData.readString(); InspectContainerResponse inspectResponse = JSONSamples.inspectContainerData. readObject(InspectContainerResponse[].class)[0]; final String containerId = inspectResponse.getId(); final String imageId = inspectResponse.getImageId(); // Retrieve instances final DockerTraceabilityRootAction action = DockerTraceabilityRootAction.getInstance(); assertNotNull(action); // Enable automatic fingerprints creation DockerTraceabilityPluginConfiguration config = new DockerTraceabilityPluginConfiguration(true, false); DockerTraceabilityPluginTest.configure(config); DockerTraceabilityPlugin plugin = DockerTraceabilityPlugin.getInstance(); assertTrue(plugin.getConfiguration().isCreateImageFingerprints()); // Submit JSON HttpResponse res = action.doSubmitContainerStatus(inspectData, null, null, null, 0, null, null); // Ensure that both container and images have been created with proper facets Fingerprint imageFP = DockerFingerprints.of(imageId); Fingerprint containerFP = DockerFingerprints.of(containerId); assertNotNull(imageFP); assertNotNull(DockerFingerprints.getFacet(imageFP, DockerDeploymentRefFacet.class)); assertNotNull(containerFP); assertNotNull(DockerFingerprints.getFacet(containerFP, DockerDeploymentFacet.class)); // TODO: JENKINS-28655 (Fingerprints cleanup) // Check original references - Docker Traceability Manager should create runs // assertNotNull(imageFP.getOriginal().getJob()); // assertNotNull(containerFP.getOriginal().getJob()); }
Example #10
Source File: DockerTraceabilityRootActionTest.java From docker-traceability-plugin with MIT License | 5 votes |
/** * Checks that the existence {@link DockerInspectImageFacet}. * @param imageId image ID * @return Facet (if validation passes) * @throws IOException test failure * @throws AssertionError Validation failure */ public DockerInspectImageFacet assertExistsInspectImageFacet (@Nonnull String imageId) throws IOException { final Fingerprint imageFP = DockerFingerprints.of(imageId); assertNotNull(imageFP); final DockerInspectImageFacet inspectImageFacet = FingerprintsHelper.getFacet(imageFP, DockerInspectImageFacet.class); assertNotNull(inspectImageFacet); assertEquals(imageId, inspectImageFacet.getData().getId()); return inspectImageFacet; }
Example #11
Source File: DockerAPIReport.java From docker-traceability-plugin with MIT License | 4 votes |
/** * Creates a report for a container. * @param containerId Container id * @return Generated report. Null if the data cannot be retrieved. */ public static @CheckForNull DockerAPIReport forContainer(@Nonnull String containerId) { Fingerprint containerFP = DockerTraceabilityHelper.of(containerId); if (containerFP == null) { return null; } DockerDeploymentFacet facet = FingerprintsHelper.getFacet(containerFP, DockerDeploymentFacet.class); if (facet == null) { return null; } final String lastStatus = facet.getLastStatus(); final DockerContainerRecord lastRecord = facet.getLatest(); if (lastRecord == null) { return null; } final DockerTraceabilityReport report = lastRecord.getReport(); final String imageId = report.getImageId(); @CheckForNull Fingerprint imageFP = null; if (imageId != null) { try { imageFP = DockerFingerprints.of(imageId); } catch (IOException ex) { // Do nothing } } final InspectImageResponse inspectImageResponse = report.getImage(); final InspectContainerResponse inspectContainerResponse = report.getContainer(); if (inspectContainerResponse == null) { return null; } final Image image = new Image(imageId, report.getImageName(), (inspectImageResponse != null) ? inspectImageResponse.getCreated() : "N/A", imageFP); final State state = new State(lastStatus, inspectContainerResponse.getState()); final Container container = new Container(inspectContainerResponse.getId(), inspectContainerResponse.getName(), inspectContainerResponse.getCreated(), containerFP, state); final Host host = new Host(report.getHostInfo().getID(), report.getHostInfo().getName()); final String environment = report.getEnvironment(); final String lastUpdate = DockerTraceabilityHelper.formatTime(report.getEvent().getTime()); return new DockerAPIReport(lastUpdate, container, image, environment, host, report.getParents()); }
Example #12
Source File: FingerprintTestUtil.java From docker-traceability-plugin with MIT License | 2 votes |
/** * Injects a {@link Fingerprint} and reference facets to the specified run. * @param run Run to be modified * @param imageId Image id * @throws IOException Error */ public static void injectFromFacet (Run run, String imageId) throws IOException { DockerFingerprints.addFromFacet(null, imageId, run); }