Skip to content

Commit efeec53

Browse files
Add Dynatrace monitoring of MTA created by (#1725)
1 parent 4e0a249 commit efeec53

8 files changed

Lines changed: 41 additions & 8 deletions

File tree

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/helpers/MtaArchiveHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
public class MtaArchiveHelper {
1515

1616
// Attribute names:
17+
private static final String ATTR_CREATED_BY = "Created-By";
1718
public static final String ATTR_MTA_RESOURCE = "MTA-Resource";
1819
public static final String ATTR_MTA_REQUIRES_DEPENDENCY = "MTA-Requires";
1920
public static final String ATTR_MTA_MODULE = "MTA-Module";
@@ -23,6 +24,10 @@ public class MtaArchiveHelper {
2324

2425
private Map<String, String> mtaArchiveResources;
2526
private Map<String, String> mtaArchiveModules;
27+
28+
public String getCreatedBy() {
29+
return this.manifest.getMainAttributes().getValue(ATTR_CREATED_BY);
30+
}
2631
private Map<String, String> mtaArchiveRequiresDependencies;
2732

2833
public MtaArchiveHelper(Manifest manifest) {

multiapps-controller-core/src/test/java/org/cloudfoundry/multiapps/controller/core/helpers/MtaArchiveHelperTest.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.stream.Stream;
2424

2525
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
import static org.junit.jupiter.api.Assertions.assertNull;
2627

2728
class MtaArchiveHelperTest {
2829

@@ -61,25 +62,34 @@ void testDependencies(String mtarLocation, String deploymentDescriptorLocation)
6162

6263
@Test
6364
void testGetResourceFileAttributes() throws IOException {
64-
Manifest manifest = getManifest();
65+
Manifest manifest = getManifest("mta-archive-helper-manifest.txt");
6566
helper = new MtaArchiveHelper(manifest);
6667
Map<String, List<String>> result = helper.getResourceFileAttributes();
6768
assertEquals(Map.of("config.json", List.of("parameters-service", "parameters-service-2")), result);
6869
}
6970

70-
private Manifest getManifest() throws IOException {
71-
InputStream fileInputStream = getClass().getResourceAsStream("mta-archive-helper-manifest.txt");
72-
return new Manifest(fileInputStream);
73-
}
74-
7571
@Test
7672
void getRequiresDependenciesFileAttributes() throws IOException {
77-
Manifest manifest = getManifest();
73+
Manifest manifest = getManifest("mta-archive-helper-manifest.txt");
7874
helper = new MtaArchiveHelper(manifest);
7975
Map<String, List<String>> result = helper.getRequiresDependenciesFileAttributes();
8076
assertEquals(Map.of("config-bind.json", List.of("anatz/my-required-application", "anatz/my-required-application-2")), result);
8177
}
8278

79+
@Test
80+
void getCreatedByAttribute() throws IOException {
81+
Manifest manifest = getManifest("mta-archive-helper-manifest-with-created-by.txt");
82+
helper = new MtaArchiveHelper(manifest);
83+
assertEquals("SAP Application Archive Builder 1.2.34", helper.getCreatedBy());
84+
}
85+
86+
@Test
87+
void getCreatedByAttributeWithNull() throws IOException {
88+
Manifest manifest = getManifest("mta-archive-helper-manifest-with-created-by-null.txt");
89+
helper = new MtaArchiveHelper(manifest);
90+
assertNull(helper.getCreatedBy());
91+
}
92+
8393
private void initializeParameters(String mtarLocation, String deploymentDescriptorLocation) {
8494
InputStream stream = getClass().getResourceAsStream(mtarLocation);
8595
helper = new MtaArchiveHelper(ArchiveHandler.getManifest(stream, ApplicationConfiguration.DEFAULT_MAX_MANIFEST_SIZE));
@@ -91,6 +101,11 @@ private void initializeParameters(String mtarLocation, String deploymentDescript
91101
helper.init();
92102
}
93103

104+
private Manifest getManifest(String file) throws IOException {
105+
InputStream fileInputStream = getClass().getResourceAsStream(file);
106+
return new Manifest(fileInputStream);
107+
}
108+
94109
private Set<String> getResourcesNamesFromDescriptor() {
95110
return descriptor.getResources()
96111
.stream()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Manifest-Version: 1.0
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Manifest-Version: 1.0
2+
Created-By: SAP Application Archive Builder 1.2.34

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/dynatrace/DynatraceProcessEvent.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.cloudfoundry.multiapps.controller.process.dynatrace;
22

3+
import org.cloudfoundry.multiapps.common.Nullable;
34
import org.immutables.value.Value;
45

56
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@@ -12,6 +13,9 @@ public abstract class DynatraceProcessEvent implements DyntraceProcessEntity {
1213

1314
public abstract EventType getEventType();
1415

16+
@Nullable
17+
public abstract String getCreatedBy();
18+
1519
public enum EventType {
1620

1721
STARTED, FINISHED, FAILED;

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/listeners/EndProcessListener.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ private void publishDynatraceEvent(DelegateExecution execution, ProcessType proc
6161
.processId(VariableHandling.get(execution,
6262
Variables.CORRELATION_ID))
6363
.mtaId(VariableHandling.get(execution, Variables.MTA_ID))
64+
.createdBy(VariableHandling.get(execution, Variables.MTA_ARCHIVE_CREATED_BY))
6465
.spaceId(VariableHandling.get(execution, Variables.SPACE_GUID))
6566
.eventType(DynatraceProcessEvent.EventType.FINISHED)
6667
.processType(processType)

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/steps/ProcessMtaArchiveStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private void processApplicationArchive(ProcessContext context, String appArchive
6060
context.getRequiredVariable(Variables.SPACE_GUID), appArchiveId);
6161
context.setVariable(Variables.ARCHIVE_ENTRIES_POSITIONS, archiveEntriesWithStreamPositions);
6262
MtaArchiveHelper helper = createMtaArchiveHelperFromManifest(context, appArchiveId, archiveEntriesWithStreamPositions);
63-
63+
context.setVariable(Variables.MTA_ARCHIVE_CREATED_BY, helper.getCreatedBy());
6464
DeploymentDescriptor deploymentDescriptor = extractDeploymentDescriptor(context, appArchiveId, archiveEntriesWithStreamPositions);
6565

6666
if (context.getVariable(Variables.SHOULD_BACKUP_PREVIOUS_VERSION)) {

multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/variables/Variables.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ public interface Variables {
338338
.type(Variable.typeReference(MtaArchiveElements.class))
339339
.defaultValue(new MtaArchiveElements())
340340
.build();
341+
Variable<String> MTA_ARCHIVE_CREATED_BY = ImmutableSimpleVariable.<String> builder()
342+
.name("mtaArchiveCreatedBy")
343+
.defaultValue(null)
344+
.build();
341345
Variable<CloudServiceInstanceExtended> SERVICE_TO_PROCESS = ImmutableJsonStringVariable.<CloudServiceInstanceExtended> builder()
342346
.name("serviceToProcess")
343347
.type(Variable.typeReference(

0 commit comments

Comments
 (0)