Skip to content

Commit

Permalink
Remove Type From native App metamodel (#2504)
Browse files Browse the repository at this point in the history
* rename method

* Function activation cleanup

* rollback file changes

* Change spark keywords

* Change spark keywords

* Fix test

* Add Primitive Type to Open APi Generator

* Add byte

* BigQuery Activator: Sandbox

* refactor modules

* refactor modules

* Add exclusions

* Move protocols

* update dependencies

* update dependencies

* Uplift Activation

* fix test

* Add deploymentLocation

* fix checkstyle errors

* fix checkstyle errors

* Cange location url

* Remove Application type

* Remove Application type

* fix dependency

* further cleanups

* clean up dependencies

* fix test

* fix test
  • Loading branch information
Yasirmod17 authored Dec 12, 2023
1 parent d0f5f8c commit 859499e
Show file tree
Hide file tree
Showing 19 changed files with 33 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ public class DeploymentResult
{
public String activatorIdentifier;
public boolean successful;
public String deploymentLocation;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@

package org.finos.legend.engine.protocol.functionActivator.deployment;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "_type")
@JsonIgnoreProperties(ignoreUnknown = true)
public class FunctionActivatorArtifact
{
public FunctionActivatorDeploymentContent content;
public FunctionActivatorDeploymentConfiguration deploymentConfiguration;
public String deployedLocation;
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ public class SnowflakeAppDeploymentManager implements DeploymentManager<Snowflak
private static final String deploymentSchema = "LEGEND_NATIVE_APPS";
private static final String deploymentTable = "APP_METADATA";

private static String deployStub = "/schemas/" + deploymentSchema + "/user-function/%S()";

private String enrichDeploymentLocation(String deploymentLocation, String appName)
{
return deploymentLocation + String.format(deployStub, appName);
}

public SnowflakeAppDeploymentManager(SnowflakeAppDeploymentTool deploymentTool)
{
this.snowflakeAppDeploymentTool = deploymentTool;
Expand Down Expand Up @@ -90,7 +97,7 @@ public SnowflakeDeploymentResult deploy(Identity identity, SnowflakeAppArtifact
this.deployImpl(jdbcConnection, (SnowflakeAppContent)artifact.content);
jdbcConnection.commit();
LOGGER.info("Completed deployment successfully");
result = new SnowflakeDeploymentResult(appName, true);
result = new SnowflakeDeploymentResult(appName, true, enrichDeploymentLocation(artifact.deployedLocation, appName));
}
catch (Exception e)
{
Expand All @@ -112,7 +119,7 @@ public SnowflakeDeploymentResult fakeDeploy(Root_meta_pure_alloy_connections_all
try
{
this.snowflakeAppDeploymentTool.deploy(datasourceSpecification, authenticationStrategy, applicationName);
return new SnowflakeDeploymentResult("",true);
return new SnowflakeDeploymentResult("",true, " ");
}
catch (Exception e)
{
Expand All @@ -139,18 +146,7 @@ public void deployImpl(Connection jdbcConnection, SnowflakeAppContent context) t
public MutableList<String> generateStatements(String catalogName, SnowflakeAppContent content)
{
MutableList<String> statements = Lists.mutable.empty();
if (content.type.equals("STAGE"))
{
String deploymentTableName = String.format("%s.%s." + deploymentTable, catalogName, deploymentSchema);
statements.add(String.format("insert into %s(CREATE_DATETIME, APP_NAME, SQL_FRAGMENT, VERSION_NUMBER, OWNER, DESCRIPTION) values('%s', '%s', '%s', '%s', '%s', '%s');",
deploymentTableName, content.creationTime, content.applicationName, content.sqlExpressions.getFirst(), content.getVersionInfo(), Lists.mutable.withAll(content.owners).makeString(","), content.description));

}
else
{
statements.add(String.format("CREATE OR REPLACE FUNCTION %S.%S.%s() RETURNS TABLE (%s) as $$ %s $$;", catalogName, deploymentSchema, content.applicationName, content.functionArguments, content.sqlExpressions.getFirst(), content.description));
statements.add(String.format("CREATE OR REPLACE SECURE FUNCTION %S.%S.%s() RETURNS TABLE (%s) as $$ %s $$;", catalogName, deploymentSchema, content.applicationName, content.functionArguments, content.sqlExpressions.getFirst(), content.description));
}
statements.add(String.format("CREATE OR REPLACE SECURE FUNCTION %S.%S.%s() RETURNS TABLE (%s) as $$ %s $$;", catalogName, deploymentSchema, content.applicationName, content.functionArguments, content.sqlExpressions.getFirst(), content.description));
return statements;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ public class SnowflakeDeploymentResult extends DeploymentResult

public MutableList<String> errors;

public SnowflakeDeploymentResult(String activatorIdentifier, boolean result)
public SnowflakeDeploymentResult(String activatorIdentifier, boolean result, String deploymentLocation)
{
this.successful = result;
this.activatorIdentifier = activatorIdentifier;
this.deploymentLocation = deploymentLocation;
}

public SnowflakeDeploymentResult(MutableList<String> errors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public Root_meta_external_function_activator_snowflakeApp_SnowflakeApp buildSnow
._function(func)
._description(app.description)
._owner(app.owner)
._type(app.type != null ? context.pureModel.getEnumValue("meta::external::function::activator::snowflakeApp::SnowflakeDeploymentType", app.type.toString()) : context.pureModel.getEnumValue("meta::external::function::activator::snowflakeApp::SnowflakeDeploymentType", "FULL"))
._activationConfiguration(app.activationConfiguration != null ? buildDeploymentConfig((SnowflakeAppDeploymentConfiguration) app.activationConfiguration, context) : null);
}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static SnowflakeAppArtifact generateArtifact(PureModel pureModel, Root_me
sdlc = (AlloySDLC) sdlcInfo;
}
}
SnowflakeAppContent content = new SnowflakeAppContent(activator._applicationName(), Lists.mutable.withAll(sqlExpressions), activator._description(), functionColumns, activator._type()._name(), Lists.mutable.with(activator._owner()), sdlc);
SnowflakeAppContent content = new SnowflakeAppContent(activator._applicationName(), Lists.mutable.withAll(sqlExpressions), activator._description(), functionColumns, Lists.mutable.with(activator._owner()), sdlc);
if (activator._activationConfiguration() != null)
{
//identify connection
Expand All @@ -67,7 +67,9 @@ public static SnowflakeAppArtifact generateArtifact(PureModel pureModel, Root_me
.getFirst();
connection = (RelationalDatabaseConnection) Lists.mutable.withAll(((PureModelContextData) inputModel).getElementsOfType(PackageableConnection.class))
.select(c -> c.getPath().equals(((org.finos.legend.engine.protocol.snowflakeApp.metamodel.SnowflakeAppDeploymentConfiguration)protocolActivator.activationConfiguration).activationConnection.connection)).getFirst().connectionValue;
return new SnowflakeAppArtifact(content, new SnowflakeAppDeploymentConfiguration(connection));
SnowflakeDatasourceSpecification ds = (SnowflakeDatasourceSpecification)connection.datasourceSpecification;
String deployedLocation = String.format("https://app.%s.privatelink.snowflakecomputing.com/%s/%s/data/databases/%S", ds.region, ds.region, ds.accountName, ds.databaseName);
return new SnowflakeAppArtifact(content, new SnowflakeAppDeploymentConfiguration(connection), deployedLocation);
}

return new SnowflakeAppArtifact(content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-protocol-pure</artifactId>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-shared-core</artifactId>
</dependency>
<!-- ENGINE -->

<!-- ECLIPSE COLLECTIONS -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SNOWFLAKE_APP__APPLICATION_NAME: 'applicationName';
SNOWFLAKE_APP__DESCRIPTION: 'description';
SNOWFLAKE_APP__FUNCTION: 'function';
SNOWFLAKE_APP__OWNER: 'owner';
SNOWFLAKE_APP__TYPE: 'type';
SNOWFLAKE_APP__ACTIVATION: 'activationConfiguration';

// ------------------------------------- CONFIGURATION -------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ identifier: VALID_STRING | STRING |
SNOWFLAKE_APP__DESCRIPTION |
SNOWFLAKE_APP__FUNCTION |
SNOWFLAKE_APP__OWNER |
SNOWFLAKE_APP__TYPE |
SNOWFLAKE_APP__ACTIVATION|
CONFIGURATION| DEPLOYMENT_STAGE
| ACTIVATION_CONNECTION |
Expand All @@ -35,7 +34,6 @@ snowflakeApp: SNOWFLAKE_APP stereotypes? taggedValues? qualifi
| description
| function
| owner
| type
| activation
)*
BRACE_CLOSE;
Expand All @@ -53,8 +51,6 @@ function: SNOWFLAKE_APP__FUNCTION COLON functionIdentifier

owner : SNOWFLAKE_APP__OWNER COLON STRING SEMI_COLON;

type : SNOWFLAKE_APP__TYPE COLON identifier SEMI_COLON;

activation: SNOWFLAKE_APP__ACTIVATION COLON qualifiedName SEMI_COLON ;

// ----------------------------------- Deployment ------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.DefaultCodeSection;
import org.finos.legend.engine.protocol.snowflakeApp.metamodel.SnowflakeApp;
import org.finos.legend.engine.protocol.snowflakeApp.metamodel.SnowflakeAppDeploymentConfiguration;
import org.finos.legend.engine.protocol.snowflakeApp.metamodel.SnowflakeAppType;
import org.finos.legend.engine.shared.core.operational.errorManagement.EngineException;

import java.util.Collections;
Expand Down Expand Up @@ -83,19 +82,6 @@ private SnowflakeApp visitSnowflakeApp(SnowflakeAppParserGrammar.SnowflakeAppCon
{
snowflakeApp.owner = PureGrammarParserUtility.fromGrammarString(ownerContext.STRING().getText(), true);
}
SnowflakeAppParserGrammar.TypeContext typeContext = PureGrammarParserUtility.validateAndExtractOptionalField(ctx.type(), "type", snowflakeApp.sourceInformation);
if (typeContext != null)
{
try
{
snowflakeApp.type = SnowflakeAppType.valueOf(PureGrammarParserUtility.fromIdentifier(typeContext.identifier()));
}
catch (Exception e)
{
throw new EngineException("Unknown type '" + PureGrammarParserUtility.fromIdentifier(typeContext.identifier()) + "'", this.walkerSourceInformation.getSourceInformation(typeContext), EngineErrorType.PARSER);
}
}

SnowflakeAppParserGrammar.DescriptionContext descriptionContext = PureGrammarParserUtility.validateAndExtractOptionalField(ctx.description(), "description", snowflakeApp.sourceInformation);
if (descriptionContext != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ private static String renderSnowflakeApp(SnowflakeApp app)
" function : " + app.function.path + ";\n" +
(app.owner == null ? "" : " owner : '" + app.owner + "';\n") +
(app.description == null ? "" : " description : '" + app.description + "';\n") +
(app.type == null ? "" : " type : " + app.type.name() + ";\n") +
(app.activationConfiguration == null ? "" : " activationConfiguration : " + ((SnowflakeAppDeploymentConfiguration)app.activationConfiguration).activationConnection.connection + ";\n") +
"}";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public void testSnowflakeApp()
" function : zxx(Integer[1]):String[1];\n" +
" owner : 'pierre';\n" +
" description : 'A super nice app!';\n" +
" type : STAGE;\n" +
" activationConfiguration : a::b::connection;\n" +
"}\n");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void testGetParserErrorWrongProperty()
"SnowflakeApp x::A\n" +
"{\n" +
" applicatioName : 'sass';\n" +
"}\n", "PARSER error at [4:4-17]: Unexpected token 'applicatioName'. Valid alternatives: ['applicationName', 'description', 'function', 'owner', 'type', 'activationConfiguration']");
"}\n", "PARSER error at [4:4-17]: Unexpected token 'applicatioName'. Valid alternatives: ['applicationName', 'description', 'function', 'owner', 'activationConfiguration']");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
<artifactId>eclipse-collections-api</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>

<!-- TEST -->
<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ public SnowflakeAppArtifact(SnowflakeAppContent content)
this.content = content;
}

public SnowflakeAppArtifact(SnowflakeAppContent content, SnowflakeAppDeploymentConfiguration config)
public SnowflakeAppArtifact(SnowflakeAppContent content, SnowflakeAppDeploymentConfiguration config, String deployedLocation)
{
this(content);
this.deploymentConfiguration = config;
this.deployedLocation = deployedLocation;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class SnowflakeAppContent extends FunctionActivatorDeploymentContent
{
public MutableList<String> sqlExpressions = Lists.mutable.empty();
public String functionArguments;
public String type;
public String applicationName;
public String description;
public List<String> owners;
Expand All @@ -41,13 +40,12 @@ public SnowflakeAppContent()
//Empty constructor for Jackson
}

public SnowflakeAppContent(String applicationName, MutableList<String> sqlExpressions, String functionArguments, String type, AlloySDLC sdlc)
public SnowflakeAppContent(String applicationName, MutableList<String> sqlExpressions, String functionArguments, AlloySDLC sdlc)
{
this.applicationName = applicationName;
this.sqlExpressions = sqlExpressions;
this.creationTime = convertToValidDate(new Date());
this.functionArguments = functionArguments;
this.type = type;
if (sdlc != null)
{
this.groupId = sdlc.groupId;
Expand All @@ -56,9 +54,9 @@ public SnowflakeAppContent(String applicationName, MutableList<String> sqlExpres
}
}

public SnowflakeAppContent(String applicationName, MutableList<String> sqlExpressions, String description, String functionArguments, String type,List<String> owners, AlloySDLC sdlc)
public SnowflakeAppContent(String applicationName, MutableList<String> sqlExpressions, String description, String functionArguments, List<String> owners, AlloySDLC sdlc)
{
this(applicationName, sqlExpressions, functionArguments, type, sdlc);
this(applicationName, sqlExpressions, functionArguments, sdlc);
this.description = description;
this.owners = owners;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,17 @@

package org.finos.legend.engine.protocol.snowflakeApp.metamodel;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.finos.legend.engine.protocol.functionActivator.metamodel.FunctionActivator;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.StereotypePtr;
import org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.TaggedValue;

import java.util.Collections;
import java.util.List;

//------------------------------------------------------------
// Should be generated out of the Pure protocol specification
//------------------------------------------------------------
@JsonIgnoreProperties(ignoreUnknown = true)
public class SnowflakeApp extends FunctionActivator
{
public String applicationName;
public String description;
public String owner;
public SnowflakeAppType type;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Class meta::external::function::activator::snowflakeApp::SnowflakeApp extends Fu
applicationName : String[1];
description : String[0..1];
owner : String[0..1];
type: SnowflakeDeploymentType[0..1] ;//default to full
}

Class meta::external::function::activator::snowflakeApp::SnowflakeDeploymentConfiguration extends DeploymentConfiguration
Expand All @@ -19,10 +18,6 @@ Class meta::external::function::activator::snowflakeApp::SnowflakeApp extends Fu

}

Enum meta::external::function::activator::snowflakeApp::SnowflakeDeploymentType
{
STAGE, FULL
}

// This section needs to be code generated from the section above
Class meta::protocols::pure::vX_X_X::metamodel::function::activator::snowflakeApp::SnowflakeApp extends meta::protocols::pure::vX_X_X::metamodel::function::activator::FunctionActivator
Expand Down

0 comments on commit 859499e

Please sign in to comment.