Search in sources :

Example 1 with PureSDLC

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;
}
Also used : LoggingEventType(org.finos.legend.engine.shared.core.operational.logs.LoggingEventType) Assert(org.finos.legend.engine.shared.core.operational.Assert) ModelLoader(org.finos.legend.engine.language.pure.modelManager.ModelLoader) CommonProfile(org.pac4j.core.profile.CommonProfile) AlloySDLCLoader(org.finos.legend.engine.language.pure.modelManager.sdlc.alloy.AlloySDLCLoader) HttpRequestHeaderMap(org.finos.legend.engine.shared.core.operational.opentracing.HttpRequestHeaderMap) MutableList(org.eclipse.collections.api.list.MutableList) Supplier(java.util.function.Supplier) EntityUtils(org.apache.http.util.EntityUtils) Function0(org.eclipse.collections.api.block.function.Function0) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) SubjectCache(org.finos.legend.engine.shared.core.kerberos.SubjectCache) PureModelContextPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextPointer) PureSDLC(org.finos.legend.engine.protocol.pure.v1.model.context.PureSDLC) PureModelContext(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpEntity(org.apache.http.HttpEntity) HTTP_HEADERS(io.opentracing.propagation.Format.Builtin.HTTP_HEADERS) GlobalTracer(io.opentracing.util.GlobalTracer) ExecSubject.exec(org.finos.legend.engine.shared.core.kerberos.ExecSubject.exec) ListIterate(org.eclipse.collections.impl.utility.ListIterate) AlloySDLC(org.finos.legend.engine.protocol.pure.v1.model.context.AlloySDLC) MetaDataServerConfiguration(org.finos.legend.engine.language.pure.modelManager.sdlc.configuration.MetaDataServerConfiguration) Subject(javax.security.auth.Subject) LogInfo(org.finos.legend.engine.shared.core.operational.logs.LogInfo) ModelManager(org.finos.legend.engine.language.pure.modelManager.ModelManager) HttpClientBuilder(org.finos.legend.engine.shared.core.kerberos.HttpClientBuilder) List(java.util.List) BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) HttpGet(org.apache.http.client.methods.HttpGet) SDLC(org.finos.legend.engine.protocol.pure.v1.model.context.SDLC) ObjectMapperFactory(org.finos.legend.engine.shared.core.ObjectMapperFactory) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) Span(io.opentracing.Span) PureServerLoader(org.finos.legend.engine.language.pure.modelManager.sdlc.pure.PureServerLoader) Scope(io.opentracing.Scope) PureModelContextPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextPointer) Scope(io.opentracing.Scope) PureSDLC(org.finos.legend.engine.protocol.pure.v1.model.context.PureSDLC) HttpClientBuilder(org.finos.legend.engine.shared.core.kerberos.HttpClientBuilder) AlloySDLC(org.finos.legend.engine.protocol.pure.v1.model.context.AlloySDLC) MutableList(org.eclipse.collections.api.list.MutableList) List(java.util.List) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Subject(javax.security.auth.Subject)

Example 2 with PureSDLC

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;
}
Also used : PureModelContextPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextPointer) PureSDLC(org.finos.legend.engine.protocol.pure.v1.model.context.PureSDLC)

Example 3 with PureSDLC

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());
}
Also used : PureModelContextPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextPointer) PureSDLC(org.finos.legend.engine.protocol.pure.v1.model.context.PureSDLC) PureModelContext(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext) ArrayList(java.util.ArrayList) PackageableElementPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer) ModelManager(org.finos.legend.engine.language.pure.modelManager.ModelManager) Protocol(org.finos.legend.engine.protocol.Protocol) Test(org.junit.Test)

Aggregations

PureModelContextPointer (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextPointer)3 PureSDLC (org.finos.legend.engine.protocol.pure.v1.model.context.PureSDLC)3 ModelManager (org.finos.legend.engine.language.pure.modelManager.ModelManager)2 PureModelContext (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Scope (io.opentracing.Scope)1 Span (io.opentracing.Span)1 HTTP_HEADERS (io.opentracing.propagation.Format.Builtin.HTTP_HEADERS)1 GlobalTracer (io.opentracing.util.GlobalTracer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Supplier (java.util.function.Supplier)1 Subject (javax.security.auth.Subject)1 HttpEntity (org.apache.http.HttpEntity)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 BasicCookieStore (org.apache.http.impl.client.BasicCookieStore)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 EntityUtils (org.apache.http.util.EntityUtils)1 Function0 (org.eclipse.collections.api.block.function.Function0)1