Search in sources :

Example 1 with AlloySDLC

use of org.finos.legend.engine.protocol.pure.v1.model.context.AlloySDLC in project legend-sdlc by finos.

the class PureModelContextDataResource method getPureModelContextData.

protected PureModelContextData getPureModelContextData(String projectId, String revisionOrVersionId, Iterable<? extends Entity> entities) {
    AlloySDLC sdlc = new AlloySDLC();
    sdlc.project = projectId;
    sdlc.baseVersion = revisionOrVersionId;
    return PureModelContextDataBuilder.newBuilder().withProtocol("pure", PureClientVersions.production).withSDLC(sdlc).withEntitiesIfPossible(entities).build();
}
Also used : AlloySDLC(org.finos.legend.engine.protocol.pure.v1.model.context.AlloySDLC)

Example 2 with AlloySDLC

use of org.finos.legend.engine.protocol.pure.v1.model.context.AlloySDLC 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)

Aggregations

AlloySDLC (org.finos.legend.engine.protocol.pure.v1.model.context.AlloySDLC)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 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 MutableList (org.eclipse.collections.api.list.MutableList)1 ListIterate (org.eclipse.collections.impl.utility.ListIterate)1 ModelLoader (org.finos.legend.engine.language.pure.modelManager.ModelLoader)1 ModelManager (org.finos.legend.engine.language.pure.modelManager.ModelManager)1