Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private boolean isCloudLoggingEnabled(DeploymentDescriptor deploymentDescriptor)
.isEmpty()
&& deploymentDescriptor.getResources()
.stream()
.anyMatch(CollectCloudLoggingServiceParametersStep::isCloudLoggingServiceResource);
.anyMatch(CollectCloudLoggingServiceParametersStep::isActiveCloudLoggingServiceResource);
}

protected LoggingConfiguration createLoggingServiceConfiguration(ProcessContext context,
Expand Down Expand Up @@ -179,11 +179,15 @@ private void updateLoggingConfiguration(ProcessContext context, LoggingConfigura

private Resource findCloudLoggingServiceResource(List<Resource> resources) {
return resources.stream()
.filter(CollectCloudLoggingServiceParametersStep::isCloudLoggingServiceResource)
.filter(CollectCloudLoggingServiceParametersStep::isActiveCloudLoggingServiceResource)
.findFirst()
.get();
}

private static boolean isActiveCloudLoggingServiceResource(Resource resource) {
return isCloudLoggingServiceResource(resource) && resource.isActive();
Comment thread
Yavor16 marked this conversation as resolved.
}

private static boolean isCloudLoggingServiceResource(Resource resource) {
ResourceType resourceType = CloudModelBuilderUtil.getResourceType(resource);
return ResourceType.CLOUD_LOGGING_SERVICE.equals(resourceType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,33 @@ void deploy_cloudLoggingResource_noUnsentEntries_doesNotForward() throws FileSto
verify(operationLogsExporter, never()).sendLogsToCloudLoggingService(any(), Mockito.<OperationLogEntry> any());
}

@Test
void deploy_inactiveCloudLoggingResource_noExistingConfig_finishesWithoutSideEffects() {
prepareDeployContext(descriptorWithInactiveCloudLogging());

step.execute(execution);

assertStepFinishedSuccessfully();
assertNull(context.getVariable(Variables.EXTERNAL_LOGGING_SERVICE_CONFIGURATION));
verify(loggingConfigurationQuery, never()).delete();
verify(auditLog, never()).logDeleteLoggingConfiguration(any(), any(), any());
verify(unsentProcessLogsProvider, never()).getUnsentProcessLogs(any());
}

@Test
void deploy_inactiveCloudLoggingResource_existingConfig_deletesExisting() {
LoggingConfiguration existing = buildConfig();
stubExistingConfig(existing);
prepareDeployContext(descriptorWithInactiveCloudLogging());

step.execute(execution);

assertStepFinishedSuccessfully();
assertNull(context.getVariable(Variables.EXTERNAL_LOGGING_SERVICE_CONFIGURATION));
verify(auditLog).logDeleteLoggingConfiguration(USER_NAME, SPACE_GUID, existing);
verify(loggingConfigurationQuery).delete();
}

private void prepareDeployContext(DeploymentDescriptor descriptor) {
when(processTypeParser.getProcessType(any())).thenReturn(ProcessType.DEPLOY);
context.setVariable(Variables.DEPLOYMENT_DESCRIPTOR, descriptor);
Expand All @@ -256,6 +283,16 @@ private static DeploymentDescriptor descriptorWithCloudLogging() {
CLOUD_LOGGING_TYPE_PARAMETER))));
}

private static DeploymentDescriptor descriptorWithInactiveCloudLogging() {
return DeploymentDescriptor.createV3()
.setResources(List.of(Resource.createV3()
.setName("my-cls")
.setType(CLOUD_LOGGING_RESOURCE_TYPE)
.setActive(false)
.setParameters(Map.of(SupportedParameters.TYPE,
CLOUD_LOGGING_TYPE_PARAMETER))));
}

private static DeploymentDescriptor descriptorWithoutCloudLogging() {
return DeploymentDescriptor.createV3()
.setResources(List.of(Resource.createV3()
Expand Down
Loading