-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DATAGO-64296: initial commit for terraform plugin #132
Changes from 20 commits
8015469
c25e365
4319153
46cd6d1
b498848
73489d0
8fdd126
13db44f
31b1a29
cf6c111
3ec624f
1eb41f3
310cece
fd3d1b4
88240bd
b96e19c
8566602
8e90b88
803d459
665dae7
008ef97
84b57d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.solace.maas.ep.common.messages; | ||
|
||
import com.solace.maas.ep.event.management.agent.plugin.command.model.CommandBundle; | ||
import com.solace.maas.ep.event.management.agent.plugin.mop.MOPMessage; | ||
import com.solace.maas.ep.event.management.agent.plugin.mop.MOPMessageType; | ||
import com.solace.maas.ep.event.management.agent.plugin.mop.MOPProtocol; | ||
import com.solace.maas.ep.event.management.agent.plugin.mop.MOPUHFlag; | ||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
public class CommandMessage extends MOPMessage { | ||
|
||
private String correlationId; | ||
private String context; | ||
private String serviceId; | ||
private List<CommandBundle> commandBundles; | ||
|
||
public CommandMessage() { | ||
super(); | ||
} | ||
|
||
public CommandMessage(String serviceId, | ||
String correlationId, | ||
String context, | ||
List<CommandBundle> commandBundles) { | ||
super(); | ||
withMessageType(MOPMessageType.generic) | ||
.withProtocol(MOPProtocol.commandProtocol) | ||
.withVersion("1") | ||
.withUhFlag(MOPUHFlag.ignore); | ||
this.serviceId = serviceId; | ||
this.correlationId = correlationId; | ||
this.context = context; | ||
this.commandBundles = commandBundles; | ||
} | ||
|
||
@Override | ||
public String toLog() { | ||
return null; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.solace.maas.ep.event.management.agent.command; | ||
|
||
import com.solace.maas.ep.event.management.agent.plugin.command.model.Command; | ||
import com.solace.maas.ep.event.management.agent.plugin.command.model.CommandBundle; | ||
import com.solace.maas.ep.event.management.agent.plugin.command.model.CommandRequest; | ||
import com.solace.maas.ep.event.management.agent.plugin.service.MessagingServiceDelegateService; | ||
import com.solace.maas.ep.event.management.agent.plugin.solace.processor.semp.SempClient; | ||
import com.solace.maas.ep.event.management.agent.plugin.solace.processor.semp.SolaceHttpSemp; | ||
import com.solace.maas.ep.event.management.agent.plugin.terraform.manager.TerraformManager; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Slf4j | ||
@Service | ||
public class CommandManager { | ||
private final TerraformManager terraformManager; | ||
|
||
private final MessagingServiceDelegateService messagingServiceDelegateService; | ||
|
||
public CommandManager(TerraformManager terraformManager, MessagingServiceDelegateService messagingServiceDelegateService) { | ||
this.terraformManager = terraformManager; | ||
this.messagingServiceDelegateService = messagingServiceDelegateService; | ||
} | ||
|
||
public void execute(CommandRequest request) { | ||
Map<String, String> envVars = setBrokerSpecificEnvVars(request.getServiceId()); | ||
for (CommandBundle bundle : request.getCommandBundles()) { | ||
// For now everything is run serially | ||
for (Command command : bundle.getCommands()) { | ||
switch (command.getCommandType()) { | ||
case terraform: | ||
terraformManager.execute(request, command, envVars); | ||
break; | ||
default: | ||
throw new IllegalStateException("Unexpected value: " + command.getCommandType()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private Map<String, String> setBrokerSpecificEnvVars(String messagingServiceId) { | ||
Map<String, String> envVars = new HashMap<>(); | ||
Object client = messagingServiceDelegateService.getMessagingServiceClient(messagingServiceId); | ||
if (client instanceof SolaceHttpSemp) { | ||
SolaceHttpSemp solaceClient = (SolaceHttpSemp) client; | ||
SempClient sempClient = solaceClient.getSempClient(); | ||
envVars.put("TF_VAR_username", sempClient.getUsername()); | ||
envVars.put("TF_VAR_password", sempClient.getPassword()); | ||
envVars.put("TF_VAR_url", sempClient.getConnectionUrl()); | ||
} | ||
return envVars; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.solace.maas.ep.event.management.agent.command.rest; | ||
|
||
import com.solace.maas.ep.event.management.agent.command.CommandManager; | ||
import com.solace.maas.ep.event.management.agent.plugin.command.model.CommandRequest; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@CrossOrigin | ||
@RestController | ||
@RequestMapping("/api/v2/ema/command") | ||
|
||
public class CommandController { | ||
private final CommandManager commandManager; | ||
|
||
public CommandController(CommandManager commandManager) { | ||
this.commandManager = commandManager; | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<CommandRequest> executeTfCommand(@RequestBody CommandRequest commandRequest) { | ||
commandManager.execute(commandRequest); | ||
return ResponseEntity.ok(commandRequest); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
import lombok.EqualsAndHashCode; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.camel.ProducerTemplate; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.slf4j.MDC; | ||
|
||
import java.util.List; | ||
|
@@ -26,14 +27,16 @@ public class StreamingAppender extends AppenderBase<ILoggingEvent> { | |
@Override | ||
protected void append(ILoggingEvent event) { | ||
if (!standalone) { | ||
if (!event.getMDCPropertyMap().get(RouteConstants.SCAN_ID).isEmpty()) { | ||
if (StringUtils.isNotEmpty(event.getMDCPropertyMap().get(RouteConstants.SCAN_ID))) { | ||
sendLogsAsync(event, | ||
event.getMDCPropertyMap().get(RouteConstants.SCAN_ID), | ||
event.getMDCPropertyMap().get(RouteConstants.TRACE_ID), | ||
event.getMDCPropertyMap().get(RouteConstants.ACTOR_ID), | ||
event.getMDCPropertyMap().get(RouteConstants.SCAN_TYPE), | ||
event.getMDCPropertyMap().get(RouteConstants.SCHEDULE_ID), | ||
event.getMDCPropertyMap().get(RouteConstants.MESSAGING_SERVICE_ID)); | ||
} else if (StringUtils.isNotEmpty(event.getMDCPropertyMap().get(RouteConstants.COMMAND_CORRELATION_ID))) { | ||
log.trace("This is a placeholder for DATAGO-64298"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the hook where we will add the terraform logs in the future. |
||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.solace.maas.ep.event.management.agent.plugin.command.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.Map; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@SuppressWarnings("PMD.AvoidFieldNameMatchingTypeName") | ||
public class Command { | ||
private CommandType commandType; // "terraform", "bash", SEMP, etc... | ||
private String command; // A tf command like `apply` or `state rm` | ||
private String body; // The body of the .tf file | ||
private Map<String, String> parameters; | ||
private Boolean ignoreResult; | ||
private CommandResult result; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.solace.maas.ep.event.management.agent.plugin.command.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CommandBundle { | ||
private ExecutionType executionType; | ||
private Boolean exitOnFailure; | ||
private List<Command> commands; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.solace.maas.ep.event.management.agent.plugin.command.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CommandRequest { | ||
private String correlationId; | ||
private String context; | ||
private String serviceId; | ||
private List<CommandBundle> commandBundles; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.solace.maas.ep.event.management.agent.plugin.command.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CommandResult { | ||
private JobStatus status; | ||
private Map<String, Object> result; | ||
private List<Map<String, Object>> logs; | ||
private List<Map<String, Object>> errors; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.solace.maas.ep.event.management.agent.plugin.command.model; | ||
|
||
public enum CommandType { | ||
terraform("terraform"); | ||
|
||
private final String type; | ||
|
||
CommandType(String type) { | ||
this.type = type; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getType(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.solace.maas.ep.event.management.agent.plugin.command.model; | ||
|
||
public enum JobStatus { | ||
in_progress, | ||
error, | ||
validation_error, | ||
success; | ||
|
||
JobStatus() { | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,9 @@ | |
public enum MOPProtocol { | ||
scanData(2850), | ||
scanDataControl(2851), | ||
EMAHeartbeat(2852); | ||
EMAHeartbeat(2852), | ||
commandProtocol(2853); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was added for future considerations when we add the messaging API |
||
|
||
|
||
private final int id; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>3.1.5</version> | ||
<relativePath /> <!-- lookup parent from repository --> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<groupId>com.solace.maas</groupId> | ||
<artifactId>maas-event-management-agent-parent</artifactId> | ||
|
@@ -18,6 +19,7 @@ | |
<module>rabbitmq-plugin</module> | ||
<module>kafka-plugin</module> | ||
<module>solace-plugin</module> | ||
<module>terraform-plugin</module> | ||
<module>local-storage-plugin</module> | ||
<module>confluent-schema-registry-plugin</module> | ||
<module>application</module> | ||
|
@@ -237,22 +239,6 @@ | |
</resources> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused execution |
||
<id>copy-docker</id> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>copy-resources</goal> | ||
</goals> | ||
<configuration> | ||
<outputDirectory>${project.build.directory}</outputDirectory> | ||
<resources> | ||
<resource> | ||
<directory>docker</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>copy-resources</id> | ||
<phase>validate</phase> | ||
|
@@ -314,7 +300,9 @@ | |
<version>3.0.0-M1</version> | ||
<configuration> | ||
<tagNameFormat>v@{project.version}</tagNameFormat> | ||
<arguments>-Dmaven.test.skip=true -Dcheckstyle.skip -Dpmd.skip -Dcpd.skip -Dfindbugs.skip -Dspotbugs.skip</arguments> | ||
<arguments>-Dmaven.test.skip=true -Dcheckstyle.skip -Dpmd.skip -Dcpd.skip -Dfindbugs.skip | ||
-Dspotbugs.skip | ||
</arguments> | ||
<scmCommentPrefix>[ci skip]</scmCommentPrefix> | ||
</configuration> | ||
</plugin> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code will be removed once the messaging I/F is added.