Skip to content

Commit

Permalink
Service Compiler Warning updates (#3262)
Browse files Browse the repository at this point in the history
* [maven-release-plugin] prepare release legend-engine-4.66.0

* [maven-release-plugin] prepare for next development iteration

* Service compilation validation changes

---------

Co-authored-by: FINOS Administrator <[email protected]>
Co-authored-by: Mauricio Uyaguari <[email protected]>
  • Loading branch information
3 people authored Nov 20, 2024
1 parent f8f951e commit b8d9ce6
Show file tree
Hide file tree
Showing 4 changed files with 261 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,12 @@ public static List<Root_meta_pure_runtime_PackageableRuntime> getMappingCompatib

public static boolean isRuntimeCompatibleWithMapping(Root_meta_pure_runtime_PackageableRuntime runtime, Mapping mappingToCheck)
{
return ListIterate.collect(runtime._runtimeValue()._mappings().toList(), mapping ->
return isRuntimeCompatibleWithMapping(runtime._runtimeValue(), mappingToCheck);
}

public static boolean isRuntimeCompatibleWithMapping(Root_meta_core_runtime_EngineRuntime runtime, Mapping mappingToCheck)
{
return ListIterate.collect(runtime._mappings().toList(), mapping ->
{
Set<Mapping> mappings = new HashSet<>();
mappings.add(mapping);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import org.apache.commons.lang3.StringUtils;
import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.impl.factory.Lists;
import org.eclipse.collections.impl.list.mutable.FastList;
import org.eclipse.collections.impl.utility.ListIterate;
import org.eclipse.collections.impl.utility.internal.IterableIterate;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.*;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.data.EmbeddedDataFirstPassBuilder;
import org.finos.legend.engine.protocol.pure.v1.model.SourceInformation;
Expand All @@ -26,6 +28,8 @@
import org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementType;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.ParameterValue;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.Runtime;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.*;
import org.finos.legend.engine.shared.core.operational.Assert;
import org.finos.legend.engine.shared.core.operational.errorManagement.EngineException;
Expand All @@ -37,6 +41,7 @@
import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.VariableExpression;

import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;

public class HelperServiceBuilder
Expand Down Expand Up @@ -79,7 +84,7 @@ private static void inferEmbeddedRuntimeMapping(org.finos.legend.engine.protocol
}
}

public static Root_meta_legend_service_metamodel_Execution processServiceExecution(Execution execution, CompileContext context)
public static Root_meta_legend_service_metamodel_Execution processServiceExecution(Execution execution, Service service, CompileContext context)
{
if (execution instanceof PureSingleExecution)
{
Expand All @@ -92,7 +97,7 @@ public static Root_meta_legend_service_metamodel_Execution processServiceExecuti
mapping = context.resolveMapping(pureSingleExecution.mapping, pureSingleExecution.mappingSourceInformation);
inferEmbeddedRuntimeMapping(pureSingleExecution.runtime, pureSingleExecution.mapping);
runtime = HelperRuntimeBuilder.buildPureRuntime(pureSingleExecution.runtime, context);
HelperRuntimeBuilder.checkRuntimeMappingCoverage(runtime, Lists.fixedSize.of(mapping), context, pureSingleExecution.runtime.sourceInformation);
checkMappingRuntimeCompatibility(() -> "Service '" + service.getPath() + "'", runtime, pureSingleExecution.runtime, mapping, pureSingleExecution.mapping, pureSingleExecution.runtime.sourceInformation, context.pureModel);
lambda = HelperValueSpecificationBuilder.buildLambda(pureSingleExecution.func, context);
}
else
Expand All @@ -119,7 +124,7 @@ else if (execution instanceof PureMultiExecution)
return new Root_meta_legend_service_metamodel_PureMultiExecution_Impl("", null, context.pureModel.getClass("meta::legend::service::metamodel::PureMultiExecution"))
._executionKey(pureMultiExecution.executionKey)
._func(lambda)
._executionParameters(ListIterate.collect(pureMultiExecution.executionParameters, executionParameter -> processServiceKeyedExecutionParameter(executionParameter, context, executionKeyValues)));
._executionParameters(ListIterate.collect(pureMultiExecution.executionParameters, executionParameter -> processServiceKeyedExecutionParameter(executionParameter, service, context, executionKeyValues)));
}
else
{
Expand All @@ -132,12 +137,13 @@ else if (execution instanceof PureMultiExecution)
.orElseThrow(() -> new UnsupportedOperationException("Unsupported service execution type '" + execution.getClass().getSimpleName() + "'"));
}

private static Root_meta_legend_service_metamodel_KeyedExecutionParameter processServiceKeyedExecutionParameter(KeyedExecutionParameter keyedExecutionParameter, CompileContext context, Set<String> executionKeyValues)
private static Root_meta_legend_service_metamodel_KeyedExecutionParameter processServiceKeyedExecutionParameter(KeyedExecutionParameter keyedExecutionParameter, Service service, CompileContext context, Set<String> executionKeyValues)
{
Mapping mapping = context.resolveMapping(keyedExecutionParameter.mapping, keyedExecutionParameter.mappingSourceInformation);
inferEmbeddedRuntimeMapping(keyedExecutionParameter.runtime, keyedExecutionParameter.mapping);
Root_meta_core_runtime_Runtime runtime = HelperRuntimeBuilder.buildPureRuntime(keyedExecutionParameter.runtime, context);
HelperRuntimeBuilder.checkRuntimeMappingCoverage(runtime, Lists.fixedSize.of(mapping), context, keyedExecutionParameter.runtime.sourceInformation);

checkMappingRuntimeCompatibility(() -> "Service '" + service.getPath() + "', key: '" + keyedExecutionParameter.key + "',", runtime, keyedExecutionParameter.runtime, mapping, keyedExecutionParameter.mapping, keyedExecutionParameter.runtime.sourceInformation, context.pureModel);
if (!executionKeyValues.add(keyedExecutionParameter.key))
{
throw new EngineException("Execution parameter with key '" + keyedExecutionParameter.key + "' already existed", keyedExecutionParameter.sourceInformation, EngineErrorType.COMPILATION);
Expand Down Expand Up @@ -191,10 +197,10 @@ public static void validateServiceTestParameterValues(CompileContext context, Li
InstanceValue paramValue = (InstanceValue) parameterValue.get()._value().getOnly();
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity paramMultiplicity = param._multiplicity();
org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.multiplicity.Multiplicity paramValueMultiplicity = paramValue._multiplicity();
if (!"Nil".equals(paramValue._genericType()._rawType()))
{
HelperModelBuilder.checkCompatibility(context, paramValue._genericType()._rawType(), paramValueMultiplicity, param._genericType()._rawType(), paramMultiplicity, "Parameter value type does not match with parameter type for parameter: '" + param._name() + "'", sourceInformation);
}
if (!"Nil".equals(paramValue._genericType()._rawType()))
{
HelperModelBuilder.checkCompatibility(context, paramValue._genericType()._rawType(), paramValueMultiplicity, param._genericType()._rawType(), paramMultiplicity, "Parameter value type does not match with parameter type for parameter: '" + param._name() + "'", sourceInformation);
}
}
else
{
Expand Down Expand Up @@ -296,14 +302,14 @@ public static Root_meta_legend_service_metamodel_ExecutionParameters processExec
{
inferEmbeddedRuntimeMapping(execParams.runtime, execParams.mapping);
Root_meta_core_runtime_Runtime runtime = HelperRuntimeBuilder.buildPureRuntime(execParams.runtime, context);
HelperRuntimeBuilder.checkRuntimeMappingCoverage(runtime, Lists.fixedSize.of(mapping), context, execParams.runtime.sourceInformation);

param._runtime(runtime);
}
else
{
Assert.assertTrue(execParams.runtimeComponents != null, () -> "Runtime components must be specified when runtime isn't");
RuntimeComponents c = execParams.runtimeComponents;
PackageableElement binding = null;
PackageableElement binding;
try
{
binding = platform_pure_essential_meta_graph_pathToElement.Root_meta_pure_functions_meta_pathToElement_String_1__PackageableElement_1_(c.binding.path, context.getExecutionSupport());
Expand Down Expand Up @@ -332,4 +338,62 @@ else if (params instanceof MultiExecutionParameters)
}
throw new UnsupportedOperationException("Unsupported service execution type '" + params.getClass().getSimpleName() + "'");
}

private static void checkMappingRuntimeCompatibility(Supplier<String> context, Root_meta_core_runtime_Runtime pureRuntime, Runtime runtime, Mapping pureMapping, String mapping, SourceInformation sourceInformation, PureModel pureModel)
{
boolean compatible = !(pureRuntime instanceof Root_meta_core_runtime_EngineRuntime) || HelperRuntimeBuilder.isRuntimeCompatibleWithMapping((Root_meta_core_runtime_EngineRuntime) pureRuntime, pureMapping);

if (!compatible)
{
String runtimeName = runtime instanceof RuntimePointer ? " '" + ((RuntimePointer) runtime).runtime + "'" : "";
pureModel.addWarnings(Lists.mutable.with(new Warning(sourceInformation, context.get() + " Runtime" + runtimeName + " does not cover mapping '" + mapping + "'")));
}
}

public static void validate(ExecutionEnvironmentInstance execEnv, Root_meta_legend_service_metamodel_ExecutionEnvironmentInstance pureExecEnv, CompileContext compileContext)
{
checkRuntimeMappingCompatibility(execEnv, pureExecEnv, compileContext);
}

public static void checkRuntimeMappingCompatibility(ExecutionEnvironmentInstance execEnv, Root_meta_legend_service_metamodel_ExecutionEnvironmentInstance pureExecEnv, CompileContext compileContext)
{
Map<String, SingleExecutionParameters> params = IterableIterate.flatCollect(execEnv.executionParameters, p ->
{
if (p instanceof SingleExecutionParameters)
{
return FastList.newListWith((SingleExecutionParameters) p);
}
else if (p instanceof MultiExecutionParameters)
{
return FastList.newList(((MultiExecutionParameters) p).singleExecutionParameters);
}
return FastList.newList();
}).groupByUniqueKey(s -> s.key);

IterableIterate.forEach(pureExecEnv._executionParameters(), e ->
{
if (e instanceof Root_meta_legend_service_metamodel_MultiExecutionParameters)
{
IterableIterate.forEach(((Root_meta_legend_service_metamodel_MultiExecutionParameters) e)._singleExecutionParameters(),
s -> checkMappingRuntimeCompatibility(execEnv, s._key(), s, params.get(s._key()), compileContext)
);
}
else if (e instanceof Root_meta_legend_service_metamodel_SingleExecutionParameters)
{
Root_meta_legend_service_metamodel_SingleExecutionParameters param = (Root_meta_legend_service_metamodel_SingleExecutionParameters) e;
checkMappingRuntimeCompatibility(execEnv, param._key(), param, params.get(param._key()), compileContext);
}
else
{
throw new UnsupportedOperationException("Unsupported service execution type '" + execEnv.getClass().getSimpleName() + "'");
}
});
}

private static void checkMappingRuntimeCompatibility(ExecutionEnvironmentInstance execEnv, String key, Root_meta_legend_service_metamodel_SingleExecutionParameters pureParam, SingleExecutionParameters param, CompileContext compileContext)
{
Root_meta_core_runtime_Runtime pureRuntime = pureParam._runtime() == null ? pureParam._runtimeComponents()._runtime() : pureParam._runtime();
Runtime runtime = param.runtime == null ? param.runtimeComponents.runtime : param.runtime;
checkMappingRuntimeCompatibility(() -> "Execution Environment '" + execEnv.getPath() + "', key: '" + key + "',", pureRuntime, runtime, pureParam._mapping(), param.mapping, runtime.sourceInformation, compileContext.pureModel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public Iterable<? extends Processor<?>> getExtraProcessors()
{
Root_meta_legend_service_metamodel_Service pureService = (Root_meta_legend_service_metamodel_Service) context.pureModel.getPackageableElement(service);

pureService._execution(HelperServiceBuilder.processServiceExecution(service.execution, context));
pureService._execution(HelperServiceBuilder.processServiceExecution(service.execution, service, context));

// Legacy flow
if (service.test != null)
Expand Down Expand Up @@ -209,6 +209,11 @@ public Iterable<? extends Processor<?>> getExtraProcessors()
{
Root_meta_legend_service_metamodel_ExecutionEnvironmentInstance pureExecEnv = (Root_meta_legend_service_metamodel_ExecutionEnvironmentInstance) context.pureModel.getPackageableElement(execEnv);
pureExecEnv._executionParameters(ListIterate.collect(execEnv.executionParameters, params -> HelperServiceBuilder.processExecutionParameters(params, context)));
},
(execEnv, context) ->
{
Root_meta_legend_service_metamodel_ExecutionEnvironmentInstance pureExecEnv = (Root_meta_legend_service_metamodel_ExecutionEnvironmentInstance) context.pureModel.getPackageableElement(execEnv);
HelperServiceBuilder.validate(execEnv, pureExecEnv, context);
})
);
}
Expand Down
Loading

0 comments on commit b8d9ce6

Please sign in to comment.