Skip to content

Commit

Permalink
Merge pull request #428 from epam/feature/add-tags-support-to-java-pl…
Browse files Browse the repository at this point in the history
…ugin

add tags support to the Syndicate Java plugin
  • Loading branch information
bohdan-onsha authored Oct 2, 2024
2 parents 169ebb3 + 6610edc commit 27177ca
Show file tree
Hide file tree
Showing 15 changed files with 139 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added validation for existence of bundle and deploy names
- Added validation for incompatible parameters(`--events`, `--resources`) of the command `syndicate status`
- Added the possibility to add resource-specific tags via the resource meta generation(flag `--tags`)
- Added tags support to the Syndicate Java plugin. The `@Tags` and the `@Tag` annotations added to the plugin. The Java plugin version updated to 1.14.0
- Changed the Java lambda template to use the Syndicate Java plugin version 1.14.0 for the new lambda generation.
- Event status added to the command `syndicate status` output
- Reworked lambda triggers update to compare local event sources meta with the previous remote one
- Reworked lambda triggers deletion to not list every resource of the trigger type to remove it from lambda (**EPMCEOOS-6112**)
Expand Down
4 changes: 2 additions & 2 deletions plugin/deployment-configuration-annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>net.sf.aws-syndicate</groupId>
<artifactId>deployment-configuration-processor</artifactId>
<version>1.13.1</version>
<version>1.14.0</version>
</parent>

<artifactId>deployment-configuration-annotations</artifactId>
<version>1.13.1</version>
<version>1.14.0</version>
<packaging>jar</packaging>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2018 EPAM Systems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.syndicate.deployment.annotations.tag;

import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Created by Roman Ivanov
*/
@Repeatable(Tags.class)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Tag {

String key();

String value();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2018 EPAM Systems, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


package com.syndicate.deployment.annotations.tag;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Created by Roman Ivanov
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Tags {

Tag[] value() default {};

}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public class LambdaConfiguration {
@JsonProperty("env_variables")
private Map<String, Object> variables;

@JsonProperty("tags")
private Map<String, String> tags;

@JsonProperty("dl_resource_name")
private String dlResourceName;

Expand Down Expand Up @@ -197,6 +200,10 @@ public Map<String, Object> getVariables() {
return variables;
}

public Map<String, String> getTags() {
return tags;
}

public String getDlResourceName() {
return dlResourceName;
}
Expand Down Expand Up @@ -388,6 +395,13 @@ public Builder withVariables(Map<String, Object> variables) {
return this;
}

public Builder withTags(Map<String, String> tags) {
Objects.requireNonNull(tags, "Tags cannot be null");
configuration.tags = tags;
return this;
}


public Builder withTracingMode(String tracingMode) {
Objects.requireNonNull(tracingMode, "Tracing mode cannot be null");
configuration.tracingMode = tracingMode;
Expand Down Expand Up @@ -473,6 +487,7 @@ public LambdaConfiguration build() {
Objects.requireNonNull(configuration.dependencies, "Dependencies cannot be null");
Objects.requireNonNull(configuration.eventSources, "Events cannot be null");
Objects.requireNonNull(configuration.variables, "Variables cannot be null");
Objects.requireNonNull(configuration.tags, "Tags cannot be null");
Objects.requireNonNull(configuration.subnetIds, "Subnet ids cannot be null");
Objects.requireNonNull(configuration.securityGroupIds, "Security group ids cannot be null");
if (configuration.alias != null && configuration.alias.equals("")) {
Expand Down Expand Up @@ -504,6 +519,7 @@ public String toString() {
", dependencies=" + dependencies +
", eventSources=" + eventSources +
", variables=" + variables +
", tags=" + tags +
", dlResourceName='" + dlResourceName + '\'' +
", dlResourceType='" + dlResourceType + '\'' +
", tracingMode='" + tracingMode + '\'' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public class TerraformLambdaConfiguration {
@JsonProperty("environment")
private Map<String, Object> environmentVariables;

@JsonProperty("tags")
private Map<String, String> tags;

@JsonProperty("dead_letter_config")
private Map<String, String> deadLetterConfig;

Expand Down Expand Up @@ -141,6 +144,15 @@ public Builder withEnvironmentVariables(Map<String, Object> environmentVariables
return this;
}

public Builder withTags(Map<String, String> tags) {
Objects.requireNonNull(tags, "Tags variables cannot be null");
if (tags.isEmpty()) {
throw new InvalidParameterException("Tags variables cannot be empty");
}
configuration.tags = tags;
return this;
}

public Builder withDeadLetterConfig(String deadLetterTargetResourceArn) {
Objects.requireNonNull(deadLetterTargetResourceArn, "Dead letter resource arn cannot be null");
configuration.deadLetterConfig = Collections.singletonMap(DL_CONFIG_ARN, deadLetterTargetResourceArn);
Expand Down Expand Up @@ -200,4 +212,9 @@ public TerraformLambdaVpcConfig getVpcConfig() {
public Map<String, Object> getEnvironmentVariables() {
return environmentVariables;
}

public Map<String, String> getTags() {
return tags;
}

}
6 changes: 3 additions & 3 deletions plugin/deployment-configuration-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>net.sf.aws-syndicate</groupId>
<artifactId>deployment-configuration-processor</artifactId>
<version>1.13.1</version>
<version>1.14.0</version>
</parent>

<artifactId>deployment-configuration-maven-plugin</artifactId>
<version>1.13.1</version>
<version>1.14.0</version>
<packaging>maven-plugin</packaging>

<properties>
Expand All @@ -28,7 +28,7 @@
<dependency>
<groupId>net.sf.aws-syndicate</groupId>
<artifactId>deployment-configuration-annotations</artifactId>
<version>1.13.1</version>
<version>1.14.0</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private LambdaConfigurationFactory() {
public static LambdaConfiguration createLambdaConfiguration(String version, Class<?> lambdaClass,
LambdaHandler lambdaHandler, Set<DependencyItem> dependencies,
Set<EventSourceItem> events, Map<String, Object> variables,
String packageName, String lambdaPath) {
Map<String, String> tags, String packageName, String lambdaPath) {
StringBuilder function = new StringBuilder(lambdaClass.getName());
String methodName = lambdaHandler.methodName();
if (!methodName.isEmpty()) {
Expand All @@ -61,7 +61,7 @@ public static LambdaConfiguration createLambdaConfiguration(String version, Clas
.withArchitectures(new Architecture[]{lambdaHandler.architecture()})
.withLogsExpirations(lambdaHandler.logsExpiration().getValue())
.withDependencies(dependencies).withEventSources(events)
.withVariables(variables).withSubnetIds(lambdaHandler.subnetsIds())
.withVariables(variables).withTags(tags).withSubnetIds(lambdaHandler.subnetsIds())
.withSecurityGroupIds(lambdaHandler.securityGroupIds())
.withPublishVersion(lambdaHandler.isPublishVersion())
.withSnapStart(lambdaHandler.snapStart())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ private Map<String, TerraformLambdaConfiguration> convertLambdaSyndicateToTerraf
if (syndicate.getVariables() != null && !syndicate.getVariables().isEmpty()) {
configurationBuilder.withEnvironmentVariables(syndicate.getVariables());
}
if (syndicate.getTags() != null && !syndicate.getTags().isEmpty()) {
configurationBuilder.withTags(syndicate.getTags());
}
if (syndicate.getDlResourceName() != null && syndicate.getDlResourceType() != null) {
configurationBuilder.withDeadLetterConfig(buildDeadLetterSourceArn(syndicate.getDlResourceName(),
syndicate.getDlResourceType(), accountId, region));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.syndicate.deployment.processor.impl;

import com.syndicate.deployment.annotations.environment.EnvironmentVariable;
import com.syndicate.deployment.annotations.tag.Tag;
import com.syndicate.deployment.model.environment.ValueTransformer;
import com.syndicate.deployment.annotations.events.DynamoDbTriggerEventSource;
import com.syndicate.deployment.annotations.events.EventBridgeRuleSource;
Expand Down Expand Up @@ -44,6 +45,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* Created by Vladyslav Tereshchenko on 10/5/2016.
Expand Down Expand Up @@ -81,8 +84,9 @@ protected Pair<String, LambdaConfiguration> process(Class<?> lambdaClass, String
dependencies.add(DependencyItemFactory.createDependencyItem(annotation));
}
Map<String, Object> envVariables = getEnvVariables(lambdaClass);
Map<String, String > tags = getTags(lambdaClass);
LambdaConfiguration lambdaConfiguration = LambdaConfigurationFactory.createLambdaConfiguration(version, lambdaClass, lambdaHandler, dependencies,
events, envVariables, fileName, path);
events, envVariables, tags, fileName, path);
return new Pair<>(lambdaHandler.lambdaName(), lambdaConfiguration);
}

Expand Down Expand Up @@ -111,4 +115,10 @@ private Object getValue(EnvironmentVariable annotation) {
"resource_type", annotation.valueTransformer().getResourceType(),
"parameter", annotation.valueTransformer().getParameter());
}

private Map<String, String> getTags(Class<?> lambdaClass) {
return Stream.of(lambdaClass.getDeclaredAnnotationsByType(Tag.class))
.collect(Collectors.toMap(Tag::key, Tag::value));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public void testSyndicateGoalExecuted() throws Exception {
.withRegionScope(RegionScope.ALL)
.build()))
.withVariables(Collections.singletonMap("name", "lambda_execute_notification"))
.withTags(Collections.singletonMap("key", "value"))
.withSubnetIds(new String[]{})
.withSecurityGroupIds(new String[]{})
.withResourceType(ResourceType.LAMBDA)
Expand Down Expand Up @@ -203,6 +204,7 @@ public void testSyndicateGoalExecuted() throws Exception {
.withRegionScope(RegionScope.ALL)
.build()))
.withVariables(Collections.singletonMap("name", "lambda_process_notification"))
.withTags(Collections.singletonMap("key", "value"))
.withSubnetIds(new String[]{})
.withSecurityGroupIds(new String[]{})
.withResourceType(ResourceType.LAMBDA)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.syndicate.deployment.annotations.events.SnsEventSource;
import com.syndicate.deployment.annotations.lambda.LambdaHandler;
import com.syndicate.deployment.annotations.resources.DependsOn;
import com.syndicate.deployment.annotations.tag.Tag;
import com.syndicate.deployment.annotations.tag.Tags;
import com.syndicate.deployment.model.LambdaSnapStart;
import com.syndicate.deployment.model.RegionScope;
import com.syndicate.deployment.model.ResourceType;
Expand All @@ -35,6 +37,7 @@
@EnvironmentVariable(key = "name", value = "lambda_execute_notification")
@DependsOn(name = "stackAuditTopic", resourceType = ResourceType.SNS_TOPIC)
@SnsEventSource(targetTopic = "stackAuditTopic", regionScope = RegionScope.ALL)
@Tags(value = {@Tag(key = "key", value = "value")})
public class SnsLambdaExecutor {
// test lambda class to be processed
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.syndicate.deployment.annotations.lambda.LambdaHandler;
import com.syndicate.deployment.annotations.resources.DeadLetterConfiguration;
import com.syndicate.deployment.annotations.resources.DependsOn;
import com.syndicate.deployment.annotations.tag.Tag;
import com.syndicate.deployment.annotations.tag.Tags;
import com.syndicate.deployment.model.DeadLetterResourceType;
import com.syndicate.deployment.model.RegionScope;
import com.syndicate.deployment.model.ResourceType;
Expand All @@ -39,6 +41,7 @@
@SnsEventSource(targetTopic = "stackAuditTopic", regionScope = RegionScope.ALL)
@DeadLetterConfiguration(resourceName = "lambda-dead-letter-queue-name",
resourceType = DeadLetterResourceType.SQS)
@Tags(value = {@Tag(key = "key", value = "value")})
public class SnsLambdaProcessor {
// test lambda class to be processed
public void handle() {
Expand Down
2 changes: 1 addition & 1 deletion plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.sf.aws-syndicate</groupId>
<artifactId>deployment-configuration-processor</artifactId>
<version>1.13.1</version>
<version>1.14.0</version>
<packaging>pom</packaging>

<name>aws-syndicate</name>
Expand Down
6 changes: 3 additions & 3 deletions syndicate/core/generators/contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
CANCEL_MESSAGE = 'Creating of {} has been canceled.'

JAVA_TAGS_IMPORT = """
import com.syndicate.deployment.annotations.lambda.Tag;
import com.syndicate.deployment.annotations.lambda.Tags;"""
import com.syndicate.deployment.annotations.tag.Tag;
import com.syndicate.deployment.annotations.tag.Tags;"""

JAVA_TAGS_ANNOTATION_TEMPLATE = """
@Tags(value = {
Expand Down Expand Up @@ -84,7 +84,7 @@
<properties>
<maven-shade-plugin.version>3.5.2</maven-shade-plugin.version>
<syndicate.java.plugin.version>1.13.0</syndicate.java.plugin.version>
<syndicate.java.plugin.version>1.14.0</syndicate.java.plugin.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down

0 comments on commit 27177ca

Please sign in to comment.