use of org.finos.legend.engine.protocol.pure.v1.model.context.PureSDLC in project legend-engine by finos.
the class SDLCLoader method load.
@Override
public PureModelContextData load(MutableList<CommonProfile> pm, PureModelContext ctx, String clientVersion, Span parentSpan) {
PureModelContextPointer context = (PureModelContextPointer) ctx;
Assert.assertTrue(clientVersion != null, () -> "Client version should be set when pulling metadata from the metadata repository");
Function0<PureModelContextData> fetchMetadata;
final Subject subject = getSubject();
if (context.sdlcInfo instanceof PureSDLC) {
fetchMetadata = () -> {
parentSpan.setTag("sdlc", "pure");
try (Scope scope = GlobalTracer.get().buildSpan("Request Pure Metadata").startActive(true)) {
return ListIterate.injectInto(new PureModelContextData.Builder(), context.sdlcInfo.packageableElementPointers, (builder, pointers) -> builder.withPureModelContextData(this.pureLoader.loadPurePackageableElementPointer(pm, pointers, clientVersion, subject == null ? "" : "?auth=kerberos"))).distinct().sorted().build();
}
};
} else if (context.sdlcInfo instanceof AlloySDLC) {
fetchMetadata = () -> {
parentSpan.setTag("sdlc", "alloy");
try (Scope scope = GlobalTracer.get().buildSpan("Request Alloy Metadata").startActive(true)) {
AlloySDLC sdlc = (AlloySDLC) context.sdlcInfo;
PureModelContextData loadedProject = this.alloyLoader.loadAlloyProject(pm, sdlc, clientVersion);
loadedProject.origin.sdlcInfo.packageableElementPointers = sdlc.packageableElementPointers;
List<String> missingPaths = this.alloyLoader.checkAllPathsExist(loadedProject, sdlc);
if (missingPaths.isEmpty()) {
return loadedProject;
} else {
throw new RuntimeException("The following PackageableElementPointers:" + missingPaths.toString() + " do not exist in the project data loaded from the metadata server");
}
}
};
} else {
throw new UnsupportedOperationException("To Code");
}
PureModelContextData metaData = subject == null ? fetchMetadata.value() : exec(subject, fetchMetadata::value);
if (metaData.origin != null) {
Assert.assertTrue("none".equals(metaData.origin.sdlcInfo.version), () -> "Version can't be set in the pointer");
metaData.origin.sdlcInfo.version = metaData.origin.sdlcInfo.baseVersion;
metaData.origin.sdlcInfo.baseVersion = null;
}
return metaData;
}
use of org.finos.legend.engine.protocol.pure.v1.model.context.PureSDLC in project legend-engine by finos.
the class PureServerLoader method getCacheKey.
public PureModelContext getCacheKey(PureModelContext context, MutableList<CommonProfile> profiles, Subject executionSubject) {
PureModelContextPointer deepCopy = new PureModelContextPointer();
PureSDLC sdlc = new PureSDLC();
sdlc.packageableElementPointers = ((PureSDLC) ((PureModelContextPointer) context).sdlcInfo).packageableElementPointers;
deepCopy.sdlcInfo = sdlc;
deepCopy.serializer = ((PureModelContextPointer) context).serializer;
deepCopy.sdlcInfo.baseVersion = this.getBaseServerVersion(profiles, executionSubject);
return deepCopy;
}
use of org.finos.legend.engine.protocol.pure.v1.model.context.PureSDLC in project legend-engine by finos.
the class TestModelManagerPureModelCaching method testPureModelCaching.
@Test
public void testPureModelCaching() {
ModelManager manager = new ModelManager(DeploymentMode.TEST, new MockModelLoader());
Protocol protocol = new Protocol("pure", "v1_17_0");
PackageableElementPointer element0 = new PackageableElementPointer(PackageableElementType.MAPPING, "meta::relational::tests::milestoning::milestoningmap");
PackageableElementPointer element1 = new PackageableElementPointer(PackageableElementType.STORE, "meta::relational::tests::dbInc");
PackageableElementPointer element2 = new PackageableElementPointer(PackageableElementType.STORE, "meta::relational::tests::db");
List<PackageableElementPointer> list = new ArrayList<>();
list.add(element0);
list.add(element1);
list.add(element2);
PureSDLC pureSDLC = new PureSDLC();
pureSDLC.packageableElementPointers = list;
PureModelContextPointer pointer = new PureModelContextPointer();
pointer.serializer = protocol;
pointer.sdlcInfo = pureSDLC;
PureModelContext context = pointer;
manager.loadModel(context, null, null, null);
Assert.assertEquals(1, manager.pureModelCache.size());
}
Aggregations