@Override protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<Void> voidHandback) { ModelNode submodel = context.readResource(PathAddress.EMPTY_ADDRESS).getModel(); //do the job return (submodel.hasDefined(Constants.ENABLED.getName()) && submodel.get(Constants.ENABLED.getName()).asBoolean()) || Constants.JNDI_NAME.getName().equals(attributeName); }
@Override public DiscardPolicy checkResource(TransformationContext context, PathAddress address) { Resource resource = context.readResourceFromRoot(address.getParent()); if (resource.hasChildren(ProxyConfigurationResourceDefinition.WILDCARD_PATH.getKey()) && resource.getChildren(ProxyConfigurationResourceDefinition.WILDCARD_PATH.getKey()).size() > 1) { return DiscardPolicy.REJECT_AND_WARN; } return DiscardPolicy.NEVER; } }
private static boolean removeInCurrentStep(Resource resource) { for (String childType : resource.getChildTypes()) { for (Resource.ResourceEntry entry : resource.getChildren(childType)) { if (!entry.isRuntime() && resource.hasChild(entry.getPathElement())) { return false; } } } return true; }
public static void removeStatisticsResources(Resource datasourceResource) { synchronized (JDBC_STATISTICS) { if (datasourceResource.hasChild(JDBC_STATISTICS)) { datasourceResource.removeChild(JDBC_STATISTICS); } if (datasourceResource.hasChild(POOL_STATISTICS)) { datasourceResource.removeChild(POOL_STATISTICS); } } }
static Resource getOrCreate(final Resource parent, final PathAddress address) { Resource current = parent; for (final PathElement element : address) { synchronized (current) { if (current.hasChild(element)) { current = current.requireChild(element); } else { final Resource resource = Resource.Factory.create(); current.registerChild(element, resource); current = resource; } } } return current; }
public static void registerStatisticsResources(Resource datasourceResource) { synchronized (JDBC_STATISTICS) { if (!datasourceResource.hasChild(JDBC_STATISTICS)) { datasourceResource.registerChild(JDBC_STATISTICS, new PlaceholderResource.PlaceholderResourceEntry(JDBC_STATISTICS)); } if (!datasourceResource.hasChild(POOL_STATISTICS)) { datasourceResource.registerChild(POOL_STATISTICS, new PlaceholderResource.PlaceholderResourceEntry(POOL_STATISTICS)); } } }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { Resource existing = context.readResource(PathAddress.EMPTY_ADDRESS); OperationStepHandler addHandler = context.getResourceRegistration().getSubModel(PathAddress.EMPTY_ADDRESS.append(newKeyName)).getOperationHandler(PathAddress.EMPTY_ADDRESS, "add"); ModelNode value = operation.get(VALUE); if (value.isDefined()) { List<ModelNode> modules = new ArrayList<ModelNode>(value.asList()); Collections.reverse(modules); //need to reverse it to make sure they are added in proper order for (ModelNode module : modules) { ModelNode addModuleOp = module.clone(); String code = addModuleOp.get(Constants.CODE).asString(); PathElement relativePath = PathElement.pathElement(newKeyName, code); PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)).append(relativePath); addModuleOp.get(OP_ADDR).set(address.toModelNode()); addModuleOp.get(OP).set(ADD); context.addStep(new ModelNode(), addModuleOp, addHandler, OperationContext.Stage.MODEL, true); } } //remove on the end to make sure it is executed first for (Resource.ResourceEntry entry : existing.getChildren(newKeyName)) { PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)).append(entry.getPathElement()); ModelNode removeModuleOp = Util.createRemoveOperation(address); context.addStep(new ModelNode(), removeModuleOp, new SecurityDomainReloadRemoveHandler(), OperationContext.Stage.MODEL, true); } } }
@Override protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException { final String attributeName = operation.require(NAME).asString(); ModelNode newValue = operation.hasDefined(VALUE) ? operation.get(VALUE) : LogStoreConstants.EXPOSE_ALL_LOGS.getDefaultValue(); final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); final ModelNode submodel = resource.getModel(); final ModelNode syntheticOp = new ModelNode(); syntheticOp.get(attributeName).set(newValue); LogStoreConstants.EXPOSE_ALL_LOGS.validateAndSet(syntheticOp, submodel); // ExposeAllRecordsAsMBeans JMX attribute will be set in LogStoreProbeHandler prior to eventual probe operation execution, // hence no need to do here anything else context.getResult().set(new ModelNode()); context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER); } }
@Override public void convert(PathAddress address, String name, ModelNode value, ModelNode model, TransformationContext context) { if (value.isDefined()) { PathAddress rootAddress = address.subAddress(0, address.size() - 4); PathAddress subsystemAddress = rootAddress.append(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "datasources")); Resource subsystem = context.readResourceFromRoot(subsystemAddress); String poolName = value.asString(); for (String type : Arrays.asList("data-source", "xa-data-source")) { if (subsystem.hasChildren(type)) { for (Resource.ResourceEntry entry : subsystem.getChildren(type)) { if (entry.getName().equals(poolName)) { value.set(entry.getModel().get("jndi-name")); return; } } } } } } };
@Override protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException { ModelNode model = resource.getModel(); final String name = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement().getValue(); final String jndiName = ContextServiceResourceDefinition.JNDI_NAME_AD.resolveModelAttribute(context, model).asString(); final boolean useTransactionSetupProvider = ContextServiceResourceDefinition.USE_TRANSACTION_SETUP_PROVIDER_AD.resolveModelAttribute(context, model).asBoolean(); // install the service which manages the default context service final ContextServiceService contextServiceService = new ContextServiceService(name, jndiName, new DefaultContextSetupProviderImpl()); final ServiceBuilder<ContextServiceImpl> serviceBuilder = context.getServiceTarget().addService(ConcurrentServiceNames.getContextServiceServiceName(name), contextServiceService); if (useTransactionSetupProvider) { // add it to deps of context service's service, for injection of its value serviceBuilder.addDependency(ConcurrentServiceNames.TRANSACTION_SETUP_PROVIDER_SERVICE_NAME,TransactionSetupProvider.class,contextServiceService.getTransactionSetupProvider()); } serviceBuilder.install(); } }
@Override public PathAddress convertToTargetAddress(PathAddress aliasAddress, AliasContext aliasContext) { PathAddress target = this.getTargetAddress(); List<PathElement> result = new ArrayList<>(aliasAddress.size()); for (int i = 0; i < aliasAddress.size(); ++i) { PathElement element = aliasAddress.getElement(i); if (i == target.size() - 1) { final ModelNode operation = aliasContext.getOperation(); final String stackName; if (ModelDescriptionConstants.ADD.equals(Operations.getName(operation)) && operation.hasDefined("type")) { stackName = operation.get("type").asString(); } else { Resource root = null; stackName = "*"; } else { Set<String> names = root.getChildrenNames("transport"); if (names.size() > 1) { throw new AssertionError("There should be at most one child"); result.add(PathElement.pathElement("transport", stackName)); } else if (i < target.size()) { PathElement targetElement = target.getElement(i); result.add(targetElement.isWildcard() ? PathElement.pathElement(targetElement.getKey(), element.getValue()) : targetElement); } else { result.add(element);
@Override public AttributeValueTranslator getWriteTranslator() { return (context, value) -> { String jndiName = value.asString(); PathAddress address = context.getCurrentAddress(); PathAddress rootAddress = address.subAddress(0, address.size() - 4); PathAddress subsystemAddress = rootAddress.append(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "datasources")); Resource subsystem = context.readResourceFromRoot(subsystemAddress); for (String type : Arrays.asList("data-source", "xa-data-source")) { if (subsystem.hasChildren(type)) { for (Resource.ResourceEntry entry : subsystem.getChildren(type)) { ModelNode model = entry.getModel(); if (model.get("jndi-name").asString().equals(jndiName)) { return new ModelNode(entry.getName()); } } } } throw InfinispanLogger.ROOT_LOGGER.dataSourceJndiNameNotFound(jndiName); }; } };
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final boolean defaults = INCLUDE_DEFAULTS.resolveModelAttribute(context,operation).asBoolean(); final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS, false); final ModelNode subModel = resource.getModel(); if (subModel.hasDefined(aliasedAttribute.getName())) { final ModelNode result = subModel.get(aliasedAttribute.getName()); context.getResult().set(result); } else if (defaults && aliasedAttribute.getDefaultValue() != null) { // No defined value in the model. See if we should reply with a default from the metadata, // reply with undefined, or fail because it's a non-existent attribute name context.getResult().set(aliasedAttribute.getDefaultValue()); } else { // model had no defined value, but we treat its existence in the model or the metadata // as proof that it's a legit attribute name context.getResult(); // this initializes the "result" to ModelType.UNDEFINED } } }
@Override public AttributeValueTranslator getReadTranslator() { return (context, value) -> { String poolName = value.asString(); PathAddress address = context.getCurrentAddress(); PathAddress rootAddress = address.subAddress(0, address.size() - 4); PathAddress subsystemAddress = rootAddress.append(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "datasources")); Resource subsystem = context.readResourceFromRoot(subsystemAddress); for (String type : Arrays.asList("data-source", "xa-data-source")) { Resource resource = subsystem.getChild(PathElement.pathElement(type, poolName)); if (resource != null) { return resource.getModel().get("jndi-name"); } } throw InfinispanLogger.ROOT_LOGGER.dataSourceNotFound(poolName); }; }
private static String getRuntimeName(final OperationContext context, final PathElement element) { final ModelNode deploymentModel = context.readResourceFromRoot(PathAddress.pathAddress(element), false).getModel(); if (!deploymentModel.hasDefined(ModelDescriptionConstants.RUNTIME_NAME)) { throw BatchLogger.LOGGER.couldNotFindDeploymentName(context.getCurrentAddress().toString()); } return deploymentModel.get(ModelDescriptionConstants.RUNTIME_NAME).asString(); } }
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { // Cache the TransactionManager service name for use by our runtime services ConnectorServices.registerCapabilityServiceName(LOCAL_TRANSACTION_PROVIDER_CAPABILITY, context.getCapabilityServiceName(LOCAL_TRANSACTION_PROVIDER_CAPABILITY, null)); final Resource subsystemResource = context.readResourceFromRoot(PathAddress.pathAddress(ResourceAdaptersExtension.SUBSYSTEM_PATH)); ResourceAdaptersSubsystemService service = new ResourceAdaptersSubsystemService(); CopyOnWriteArrayListMultiMap<String, ServiceName> value = service.getValue(); for (Resource.ResourceEntry re : subsystemResource.getChildren(RESOURCEADAPTER_NAME)) { value.putIfAbsent(re.getModel().get(ARCHIVE.getName()).asString(), ConnectorServices.RA_SERVICE.append(re.getName())); } final ServiceBuilder<?> builder = context.getServiceTarget().addService(ConnectorServices.RESOURCEADAPTERS_SUBSYSTEM_SERVICE, service); builder.setInitialMode(ServiceController.Mode.ACTIVE).install(); } }
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder builder) { if (InfinispanModel.VERSION_6_0_0.requiresTransformation(version)) { Converter converter = (PathAddress address, String name, ModelNode value, ModelNode model, TransformationContext context) -> { PathAddress storeAddress = address.getParent(); PathElement storePath = storeAddress.getLastElement(); if (storePath.equals(StringKeyedJDBCStoreResourceDefinition.STRING_JDBC_PATH) || storePath.equals(StringKeyedJDBCStoreResourceDefinition.LEGACY_PATH)) { storeAddress = storeAddress.getParent().append(StringKeyedJDBCStoreResourceDefinition.PATH); } else if (storePath.equals(BinaryKeyedJDBCStoreResourceDefinition.LEGACY_PATH)) { storeAddress = storeAddress.getParent().append(BinaryKeyedJDBCStoreResourceDefinition.PATH); } else if (storePath.equals(MixedKeyedJDBCStoreResourceDefinition.LEGACY_PATH)) { storeAddress = storeAddress.getParent().append(MixedKeyedJDBCStoreResourceDefinition.PATH); } ModelNode store = context.readResourceFromRoot(storeAddress).getModel(); value.set(store.hasDefined(StoreResourceDefinition.Attribute.MAX_BATCH_SIZE.getName()) ? store.get(StoreResourceDefinition.Attribute.MAX_BATCH_SIZE.getName()) : StoreResourceDefinition.Attribute.MAX_BATCH_SIZE.getDefinition().getDefaultValue()); }; builder.getAttributeBuilder().setValueConverter(new SimpleAttributeConverter(converter), DeprecatedAttribute.BATCH_SIZE.getDefinition()); } }
private boolean checkJtsEnabled(final OperationContext context) { try { final ModelNode jtsNode = context.readResourceFromRoot(PathAddress.pathAddress("subsystem", "transactions"), false) .getModel().get("jts"); return jtsNode.isDefined() ? jtsNode.asBoolean() : false; } catch (NoSuchResourceException ex) { return false; } } }
/** * Resolves runtime name of model resource. * @param context - operation context in which handler is invoked * @param address - deployment address * @return runtime name of module. Value which is returned is never null. */ protected static String resolveRuntimeName(final OperationContext context, final PathElement address){ final ModelNode runtimeName = context.readResourceFromRoot(PathAddress.pathAddress(address),false).getModel() .get(ModelDescriptionConstants.RUNTIME_NAME); return runtimeName.asString(); } }
@Override protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException { ModelNode model = resource.getModel(); CapabilityServiceTarget target = context.getCapabilityServiceTarget(); final String securityDomain = SECURITY_DOMAIN.resolveModelAttribute(context, model).asStringOrNull(); final String httpServerMechanismFactory = HTTP_AUTHENTICATION_FACTORY.resolveModelAttribute(context, model).asStringOrNull(); boolean overrideDeploymentConfig = OVERRIDE_DEPLOYMENT_CONFIG.resolveModelAttribute(context, model).asBoolean(); boolean enableJacc = ENABLE_JACC.resolveModelAttribute(context, model).asBoolean(); boolean enableJaspi = ENABLE_JASPI.resolveModelAttribute(context, model).asBoolean(); boolean integratedJaspi = INTEGRATED_JASPI.resolveModelAttribute(context, model).asBoolean(); String securityDomainName = context.getCurrentAddressValue(); ServiceName applicationSecurityDomainName = APPLICATION_SECURITY_DOMAIN_RUNTIME_CAPABILITY.getCapabilityServiceName(context.getCurrentAddress()); if (resource.hasChild(UndertowExtension.PATH_SSO)) { ModelNode ssoModel = resource.getChild(UndertowExtension.PATH_SSO).getModel(); String cookieName = SingleSignOnDefinition.Attribute.COOKIE_NAME.resolveModelAttribute(context, ssoModel).asString();