Search in sources :

Example 1 with ContentType

use of org.jboss.as.patching.metadata.ContentType in project wildfly-core by wildfly.

the class PatchStepAssertions method assertContentModification.

static void assertContentModification(final String patchID, final PatchableTarget target, final ContentModification modification) {
    final ContentItem item = modification.getItem();
    final ContentType contentType = item.getContentType();
    switch(contentType) {
        case MODULE:
            assertModule(patchID, target, (ModuleItem) item);
            break;
        case BUNDLE:
            break;
        case MISC:
            final File home = target.getDirectoryStructure().getInstalledImage().getJbossHome();
            final ModificationCondition condition = modification.getCondition();
            if (condition != null) {
                if (condition instanceof ModificationCondition.ExistsCondition) {
                    final ContentItem requiredItem = ((ModificationCondition.ExistsCondition) condition).getContentItem();
                    File requiredFile;
                    switch(requiredItem.getContentType()) {
                        case MISC:
                            requiredFile = PatchContentLoader.getMiscPath(home, (MiscContentItem) requiredItem);
                            break;
                        case MODULE:
                        case BUNDLE:
                        default:
                            throw new IllegalStateException("Unsupported content type");
                    }
                    if (!requiredFile.exists()) {
                        final File file = PatchContentLoader.getMiscPath(home, (MiscContentItem) item);
                        Assert.assertFalse(file.exists());
                        return;
                    }
                }
            }
            assertMisc(home, modification.getType(), (MiscContentItem) item);
            break;
        default:
            Assert.fail();
    }
}
Also used : ContentType(org.jboss.as.patching.metadata.ContentType) ModificationCondition(org.jboss.as.patching.metadata.ModificationCondition) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) File(java.io.File) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ContentItem(org.jboss.as.patching.metadata.ContentItem)

Example 2 with ContentType

use of org.jboss.as.patching.metadata.ContentType in project wildfly-core by wildfly.

the class Location method hashCode.

static int hashCode(final ContentItem item) {
    final ContentType type = item.getContentType();
    switch(type) {
        case MODULE:
        case BUNDLE:
            final ModuleItem module = (ModuleItem) item;
            final String[] path = module.getName().split("\\.");
            return hashCode(type.toString(), module.getSlot(), path);
        case MISC:
            final MiscContentItem misc = (MiscContentItem) item;
            return hashCode(type.toString(), misc.getName(), misc.getPath());
        default:
            throw new IllegalStateException();
    }
}
Also used : ModuleItem(org.jboss.as.patching.metadata.ModuleItem) ContentType(org.jboss.as.patching.metadata.ContentType) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem)

Example 3 with ContentType

use of org.jboss.as.patching.metadata.ContentType in project wildfly-core by wildfly.

the class ContentPolicyBuilderImpl method createPolicy.

@Override
public ContentVerificationPolicy createPolicy() {
    return new ContentVerificationPolicy() {

        @Override
        public boolean ignoreContentValidation(ContentItem item) {
            final ContentType type = item.getContentType();
            if (type == ContentType.MODULE || type == ContentType.BUNDLE) {
                return ignoreModulesChanges || overrideAll;
            }
            final MiscContentItem misc = (MiscContentItem) item;
            final String path = misc.getRelativePath();
            if (override.contains(path)) {
                return true;
            }
            // Preserve should skip content verification
            if (preserve.contains(path)) {
                return true;
            }
            return overrideAll;
        }

        @Override
        public boolean preserveExisting(ContentItem item) {
            final ContentType type = item.getContentType();
            if (type == ContentType.MISC) {
                final MiscContentItem misc = (MiscContentItem) item;
                final String path = misc.getRelativePath();
                return preserve.contains(path);
            }
            return false;
        }
    };
}
Also used : ContentType(org.jboss.as.patching.metadata.ContentType) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ContentItem(org.jboss.as.patching.metadata.ContentItem)

Example 4 with ContentType

use of org.jboss.as.patching.metadata.ContentType in project wildfly-core by wildfly.

the class PatchOperationTarget method formatFailedResponse.

public static void formatFailedResponse(final PatchingException e, final ModelNode failureDescription) {
    if (e instanceof ContentConflictsException) {
        failureDescription.get(Constants.MESSAGE).set(PatchLogger.ROOT_LOGGER.detectedConflicts());
        final ModelNode conflicts = failureDescription.get(Constants.CONFLICTS);
        for (final ContentItem item : ((ContentConflictsException) e).getConflicts()) {
            final ContentType type = item.getContentType();
            switch(type) {
                case BUNDLE:
                    conflicts.get(Constants.BUNDLES).add(item.getRelativePath());
                    break;
                case MODULE:
                    conflicts.get(Constants.MODULES).add(item.getRelativePath());
                    break;
                case MISC:
                    conflicts.get(Constants.MISC).add(item.getRelativePath());
                    break;
            }
        }
    } else {
        failureDescription.set(e.getLocalizedMessage());
    }
}
Also used : ContentType(org.jboss.as.patching.metadata.ContentType) ContentConflictsException(org.jboss.as.patching.ContentConflictsException) ModelNode(org.jboss.dmr.ModelNode) ContentItem(org.jboss.as.patching.metadata.ContentItem)

Aggregations

ContentType (org.jboss.as.patching.metadata.ContentType)4 ContentItem (org.jboss.as.patching.metadata.ContentItem)3 MiscContentItem (org.jboss.as.patching.metadata.MiscContentItem)3 File (java.io.File)1 ContentConflictsException (org.jboss.as.patching.ContentConflictsException)1 ModificationCondition (org.jboss.as.patching.metadata.ModificationCondition)1 ModuleItem (org.jboss.as.patching.metadata.ModuleItem)1 ModelNode (org.jboss.dmr.ModelNode)1