use of org.jboss.as.patching.installation.PatchableTarget in project wildfly-core by wildfly.
the class PatchStepAssertions method assertApplied.
static void assertApplied(final Patch patch, InstallationManager manager) throws IOException {
final String patchID = patch.getPatchId();
InstalledIdentity installedIdentity = null;
try {
installedIdentity = manager.getInstalledIdentity(patch.getIdentity().getName(), null);
} catch (PatchingException e) {
Assert.fail(e.getLocalizedMessage());
}
final PatchableTarget target = installedIdentity.getIdentity();
final PatchableTarget.TargetInfo identity = target.loadTargetInfo();
assertIsApplied(patch.getIdentity().getPatchType(), patchID, identity);
assertExists(identity.getDirectoryStructure().getInstalledImage().getPatchHistoryDir(patchID));
assertContentItems(patchID, target, patch.getModifications());
for (final PatchElement element : patch.getElements()) {
final PatchElementProvider provider = element.getProvider();
final PatchableTarget targetElement = provider.isAddOn() ? installedIdentity.getAddOn(provider.getName()) : installedIdentity.getLayer(provider.getName());
assertIsApplied(provider.getPatchType(), element.getId(), targetElement.loadTargetInfo());
assertContentItems(element.getId(), targetElement, element.getModifications());
}
}
use of org.jboss.as.patching.installation.PatchableTarget in project wildfly-core by wildfly.
the class PatchUndoTestCase method testWrongMiscContent.
@Test
public void testWrongMiscContent() throws Exception {
final PatchingTestBuilder builder = createDefaultBuilder();
ContentModificationUtils.addMisc(builder.getRoot(), "oo2", "test-content", "wrong-content");
final MiscContentItem item = new MiscContentItem("wrong-content", new String[0], WRONG_HASH);
final ContentModification wrongModification = new ContentModification(item, IoUtils.NO_CONTENT, ModificationType.ADD);
final PatchingTestStepBuilder step1 = builder.createStepBuilder();
step1.oneOffPatchIdentity(PRODUCT_VERSION).setPatchId("oo2").oneOffPatchElement("base-patch-002", "base", false).addModuleWithRandomContent("other.test", null).getParent().addFileWithRandomContent(null, "test", "content").addContentModification(wrongModification);
//
try {
apply(step1);
Assert.fail("should have failed");
} catch (PatchingException e) {
Assert.assertFalse(builder.hasFile("test", "content"));
Assert.assertFalse(builder.hasFile("wrong-content"));
final InstalledIdentity identity = loadInstallationManager().getDefaultIdentity();
final PatchableTarget base = identity.getLayer("base");
Assert.assertFalse(base.getDirectoryStructure().getModulePatchDirectory("base-patch-002").exists());
Assert.assertFalse(identity.getInstalledImage().getPatchHistoryDir("oo2").exists());
}
}
use of org.jboss.as.patching.installation.PatchableTarget in project wildfly-core by wildfly.
the class PatchableTargetsArtifact method process.
@Override
public boolean process(PatchingXmlArtifact.XmlArtifactState<Patch> parent, PatchingArtifactProcessor processor) {
final InstalledIdentity identity = processor.getValidationContext().getInstalledIdentity();
final Patch patch = parent.getPatch();
if (Constants.BASE.equals(patch.getPatchId())) {
return true;
}
final List<PatchElement> elements = patch.getElements();
boolean valid = true;
if (elements != null && !elements.isEmpty()) {
for (final PatchElement element : elements) {
final String patchID = element.getId();
final PatchElementProvider provider = element.getProvider();
final String layerName = provider.getName();
final PatchableTarget target = provider.isAddOn() ? identity.getAddOn(layerName) : identity.getLayer(layerName);
boolean modules = false;
boolean bundles = false;
for (final ContentModification modification : element.getModifications()) {
if (modules && bundles) {
break;
}
if (modification.getItem().getContentType() == ContentType.BUNDLE) {
bundles = true;
} else if (modification.getItem().getContentType() == ContentType.MODULE) {
modules = true;
}
}
final PatchableTargetState state = new PatchableTargetState(patchID, layerName, target, bundles, modules);
if (!processor.process(PatchingArtifacts.LAYER, state)) {
valid = false;
}
}
}
// In case there are misc content modifications also validate that misc backup exists
for (final ContentModification modification : patch.getModifications()) {
if (modification.getType() != ModificationType.ADD && modification.getItem().getContentType() == ContentType.MISC) {
final PatchingHistoryDirArtifact.DirectoryArtifactState history = processor.getParentArtifact(PatchingArtifacts.HISTORY_DIR);
PatchingArtifacts.MISC_BACKUP.process(history, processor);
break;
}
}
return valid;
}
use of org.jboss.as.patching.installation.PatchableTarget in project wildfly-core by wildfly.
the class ElementProviderAttributeReadHandler method execute.
@Override
protected void execute(final OperationContext context, final ModelNode operation, final InstalledIdentity installedIdentity) throws OperationFailedException {
final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
final PathElement element = address.getLastElement();
final String name = element.getValue();
PatchableTarget target = getProvider(name, installedIdentity);
final ModelNode result = context.getResult();
handle(result, target);
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
use of org.jboss.as.patching.installation.PatchableTarget in project wildfly-core by wildfly.
the class PatchResourceDefinition method registerPatchingChildren.
private void registerPatchingChildren(ManagementResourceRegistration registry) {
StandardResourceDescriptionResolver resolver = new StandardResourceDescriptionResolver("patching.layer", "org.jboss.as.patching.management.LocalDescriptions", PatchResourceDefinition.class.getClassLoader());
registry.registerSubModel(new SimpleResourceDefinition(new Parameters(PathElement.pathElement("layer"), resolver).setAccessConstraints(SensitiveTargetAccessConstraintDefinition.PATCHING).setRuntime()) {
@Override
public void registerAttributes(final ManagementResourceRegistration resource) {
resource.registerReadOnlyAttribute(CUMULATIVE_PATCH_ID, new ElementProviderAttributeReadHandler.LayerAttributeReadHandler() {
@Override
void handle(ModelNode result, PatchableTarget layer) throws OperationFailedException {
try {
result.set(layer.loadTargetInfo().getCumulativePatchID());
} catch (IOException e) {
throw new OperationFailedException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(layer.getName()), e);
}
}
});
resource.registerReadOnlyAttribute(PATCHES, new ElementProviderAttributeReadHandler.LayerAttributeReadHandler() {
@Override
void handle(ModelNode result, PatchableTarget layer) throws OperationFailedException {
result.setEmptyList();
try {
for (final String id : layer.loadTargetInfo().getPatchIDs()) {
result.add(id);
}
} catch (IOException e) {
throw new OperationFailedException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(layer.getName()), e);
}
}
});
}
});
resolver = new StandardResourceDescriptionResolver("patching.addon", "org.jboss.as.patching.management.LocalDescriptions", PatchResourceDefinition.class.getClassLoader());
registry.registerSubModel(new SimpleResourceDefinition(new Parameters(PathElement.pathElement("addon"), resolver).setAccessConstraints(SensitiveTargetAccessConstraintDefinition.PATCHING).setRuntime()) {
@Override
public void registerAttributes(final ManagementResourceRegistration resource) {
resource.registerReadOnlyAttribute(CUMULATIVE_PATCH_ID, new ElementProviderAttributeReadHandler.AddOnAttributeReadHandler() {
@Override
void handle(ModelNode result, PatchableTarget addon) throws OperationFailedException {
try {
result.set(addon.loadTargetInfo().getCumulativePatchID());
} catch (IOException e) {
throw new OperationFailedException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(addon.getName()), e);
}
}
});
resource.registerReadOnlyAttribute(PATCHES, new ElementProviderAttributeReadHandler.AddOnAttributeReadHandler() {
@Override
void handle(ModelNode result, PatchableTarget addon) throws OperationFailedException {
result.setEmptyList();
try {
for (final String id : addon.loadTargetInfo().getPatchIDs()) {
result.add(id);
}
} catch (IOException e) {
throw new OperationFailedException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(addon.getName()), e);
}
}
});
}
});
}
Aggregations