@Test public void testExecuteTransaction_WithVariousVirtualSystems_ExpectsCorrectTaskGraph() throws Exception { OsImageCheckMetaTask task = new OsImageCheckMetaTask(this.vs, this.region, this.osEndPoint, this.glanceMock); task.uploadImageToGlanceTask = new UploadImageToGlanceTask(); task.deleteImageReferenceTask = new DeleteImageReferenceTask(); task.deleteImageFromGlanceTask = new DeleteImageFromGlanceTask(); task.updateVsWithImageVersionTask = new UpdateVsWithImageVersionTask(); task.executeTransaction(this.em); TaskGraphHelper.validateTaskGraph(task, this.expectedGraph); }
@Override public void executeTransaction(EntityManager em) throws Exception { this.tg = new TaskGraph(); this.vs = em.find(VirtualSystem.class, this.vs.getId()); LOG.info("Checking VS " + this.vs.getName() + " has the corresponding image uploaded in glance"); ApplianceSoftwareVersion applianceSoftwareVersion = this.vs.getApplianceSoftwareVersion(); String expectedGlanceImageName = Joiner.on("-").join(applianceSoftwareVersion.getAppliance().getModel(), applianceSoftwareVersion.getApplianceSoftwareVersion(), this.vs.getName(), applianceSoftwareVersion.getImageUrl()); if (this.glance == null) { this.glance = new Openstack4jGlance(this.osEndPoint); } Set<OsImageReference> imageReferences = this.vs.getOsImageReference(); boolean uploadImage = true; try { for (OsImageReference imageReference : imageReferences) { if (imageReference.getRegion().equals(this.region)) { Image image = this.glance.getImageById(imageReference.getRegion(), imageReference.getImageRefId()); if (image == null || image.getStatus() != Image.ImageStatus.ACTIVE) { this.tg.appendTask(this.deleteImageReferenceTask.create(imageReference, this.vs)); } else if (!image.getName().equals(expectedGlanceImageName)) { this.tg.appendTask(this.deleteImageFromGlanceTask.create(this.region, imageReference, this.osEndPoint)); } else { uploadImage = false; } } } } finally { this.glance.close(); } if (uploadImage) { this.tg.appendTask(this.uploadImageToGlanceTask.create(this.vs, this.region, expectedGlanceImageName, applianceSoftwareVersion, this.osEndPoint), TaskGuard.ALL_PREDECESSORS_COMPLETED); } else if (!imageReferences.isEmpty()) { this.tg.appendTask(this.updateVsWithImageVersionTask.create(this.vs)); } }
OsImageCheckMetaTask extends TransactionalMetaTask { @Override public void executeTransaction(EntityManager em) throws Exception { this.tg = new TaskGraph(); this.vs = em.find(VirtualSystem.class, this.vs.getId()); LOG.info("Checking VS " + this.vs.getName() + " has the corresponding image uploaded in glance"); ApplianceSoftwareVersion applianceSoftwareVersion = this.vs.getApplianceSoftwareVersion(); String expectedGlanceImageName = Joiner.on("-").join(applianceSoftwareVersion.getAppliance().getModel(), applianceSoftwareVersion.getApplianceSoftwareVersion(), this.vs.getName(), applianceSoftwareVersion.getImageUrl()); if (this.glance == null) { this.glance = new Openstack4jGlance(this.osEndPoint); } Set<OsImageReference> imageReferences = this.vs.getOsImageReference(); boolean uploadImage = true; try { for (OsImageReference imageReference : imageReferences) { if (imageReference.getRegion().equals(this.region)) { Image image = this.glance.getImageById(imageReference.getRegion(), imageReference.getImageRefId()); if (image == null || image.getStatus() != Image.ImageStatus.ACTIVE) { this.tg.appendTask(this.deleteImageReferenceTask.create(imageReference, this.vs)); } else if (!image.getName().equals(expectedGlanceImageName)) { this.tg.appendTask(this.deleteImageFromGlanceTask.create(this.region, imageReference, this.osEndPoint)); } else { uploadImage = false; } } } } finally { this.glance.close(); } if (uploadImage) { this.tg.appendTask(this.uploadImageToGlanceTask.create(this.vs, this.region, expectedGlanceImageName, applianceSoftwareVersion, this.osEndPoint), TaskGuard.ALL_PREDECESSORS_COMPLETED); } else if (!imageReferences.isEmpty()) { this.tg.appendTask(this.updateVsWithImageVersionTask.create(this.vs)); } } }
OsImageCheckMetaTask extends TransactionalMetaTask { @Override public void executeTransaction(EntityManager em) throws Exception { this.tg = new TaskGraph(); this.vs = em.find(VirtualSystem.class, this.vs.getId()); LOG.info("Checking VS " + this.vs.getName() + " has the corresponding image uploaded in glance"); ApplianceSoftwareVersion applianceSoftwareVersion = this.vs.getApplianceSoftwareVersion(); String expectedGlanceImageName = Joiner.on("-").join(applianceSoftwareVersion.getAppliance().getModel(), applianceSoftwareVersion.getApplianceSoftwareVersion(), this.vs.getName(), applianceSoftwareVersion.getImageUrl()); if (this.glance == null) { this.glance = new Openstack4jGlance(this.osEndPoint); } Set<OsImageReference> imageReferences = this.vs.getOsImageReference(); boolean uploadImage = true; try { for (OsImageReference imageReference : imageReferences) { if (imageReference.getRegion().equals(this.region)) { Image image = this.glance.getImageById(imageReference.getRegion(), imageReference.getImageRefId()); if (image == null || image.getStatus() != Image.ImageStatus.ACTIVE) { this.tg.appendTask(this.deleteImageReferenceTask.create(imageReference, this.vs)); } else if (!image.getName().equals(expectedGlanceImageName)) { this.tg.appendTask(this.deleteImageFromGlanceTask.create(this.region, imageReference, this.osEndPoint)); } else { uploadImage = false; } } } } finally { this.glance.close(); } if (uploadImage) { this.tg.appendTask(this.uploadImageToGlanceTask.create(this.vs, this.region, expectedGlanceImageName, applianceSoftwareVersion, this.osEndPoint), TaskGuard.ALL_PREDECESSORS_COMPLETED); } else if (!imageReferences.isEmpty()) { this.tg.appendTask(this.updateVsWithImageVersionTask.create(this.vs)); } } OsImageCheckMetaTask();   OsImageCheckMetaTask(VirtualSystem vs, String region, Endpoint osEndPoint, Openstack4jGlance glance); }
OsImageCheckMetaTask extends TransactionalMetaTask { @Override public void executeTransaction(EntityManager em) throws Exception { this.tg = new TaskGraph(); this.vs = em.find(VirtualSystem.class, this.vs.getId()); LOG.info("Checking VS " + this.vs.getName() + " has the corresponding image uploaded in glance"); ApplianceSoftwareVersion applianceSoftwareVersion = this.vs.getApplianceSoftwareVersion(); String expectedGlanceImageName = Joiner.on("-").join(applianceSoftwareVersion.getAppliance().getModel(), applianceSoftwareVersion.getApplianceSoftwareVersion(), this.vs.getName(), applianceSoftwareVersion.getImageUrl()); if (this.glance == null) { this.glance = new Openstack4jGlance(this.osEndPoint); } Set<OsImageReference> imageReferences = this.vs.getOsImageReference(); boolean uploadImage = true; try { for (OsImageReference imageReference : imageReferences) { if (imageReference.getRegion().equals(this.region)) { Image image = this.glance.getImageById(imageReference.getRegion(), imageReference.getImageRefId()); if (image == null || image.getStatus() != Image.ImageStatus.ACTIVE) { this.tg.appendTask(this.deleteImageReferenceTask.create(imageReference, this.vs)); } else if (!image.getName().equals(expectedGlanceImageName)) { this.tg.appendTask(this.deleteImageFromGlanceTask.create(this.region, imageReference, this.osEndPoint)); } else { uploadImage = false; } } } } finally { this.glance.close(); } if (uploadImage) { this.tg.appendTask(this.uploadImageToGlanceTask.create(this.vs, this.region, expectedGlanceImageName, applianceSoftwareVersion, this.osEndPoint), TaskGuard.ALL_PREDECESSORS_COMPLETED); } else if (!imageReferences.isEmpty()) { this.tg.appendTask(this.updateVsWithImageVersionTask.create(this.vs)); } } OsImageCheckMetaTask();   OsImageCheckMetaTask(VirtualSystem vs, String region, Endpoint osEndPoint, Openstack4jGlance glance); OsImageCheckMetaTask create(VirtualSystem vs, String region, Endpoint osEndPoint); @Override void executeTransaction(EntityManager em); @Override String getName(); @Override TaskGraph getTaskGraph(); @Override Set<LockObjectReference> getObjects(); }
OsImageCheckMetaTask extends TransactionalMetaTask { @Override public void executeTransaction(EntityManager em) throws Exception { this.tg = new TaskGraph(); this.vs = em.find(VirtualSystem.class, this.vs.getId()); LOG.info("Checking VS " + this.vs.getName() + " has the corresponding image uploaded in glance"); ApplianceSoftwareVersion applianceSoftwareVersion = this.vs.getApplianceSoftwareVersion(); String expectedGlanceImageName = Joiner.on("-").join(applianceSoftwareVersion.getAppliance().getModel(), applianceSoftwareVersion.getApplianceSoftwareVersion(), this.vs.getName(), applianceSoftwareVersion.getImageUrl()); if (this.glance == null) { this.glance = new Openstack4jGlance(this.osEndPoint); } Set<OsImageReference> imageReferences = this.vs.getOsImageReference(); boolean uploadImage = true; try { for (OsImageReference imageReference : imageReferences) { if (imageReference.getRegion().equals(this.region)) { Image image = this.glance.getImageById(imageReference.getRegion(), imageReference.getImageRefId()); if (image == null || image.getStatus() != Image.ImageStatus.ACTIVE) { this.tg.appendTask(this.deleteImageReferenceTask.create(imageReference, this.vs)); } else if (!image.getName().equals(expectedGlanceImageName)) { this.tg.appendTask(this.deleteImageFromGlanceTask.create(this.region, imageReference, this.osEndPoint)); } else { uploadImage = false; } } } } finally { this.glance.close(); } if (uploadImage) { this.tg.appendTask(this.uploadImageToGlanceTask.create(this.vs, this.region, expectedGlanceImageName, applianceSoftwareVersion, this.osEndPoint), TaskGuard.ALL_PREDECESSORS_COMPLETED); } else if (!imageReferences.isEmpty()) { this.tg.appendTask(this.updateVsWithImageVersionTask.create(this.vs)); } } OsImageCheckMetaTask();   OsImageCheckMetaTask(VirtualSystem vs, String region, Endpoint osEndPoint, Openstack4jGlance glance); OsImageCheckMetaTask create(VirtualSystem vs, String region, Endpoint osEndPoint); @Override void executeTransaction(EntityManager em); @Override String getName(); @Override TaskGraph getTaskGraph(); @Override Set<LockObjectReference> getObjects();  }