Skip to content

Commit b9b7baa

Browse files
committed
fixing comments
1 parent 86f0be4 commit b9b7baa

File tree

7 files changed

+51
-194
lines changed

7 files changed

+51
-194
lines changed

multiapps-controller-api/src/main/resources/mtarest.yaml

Lines changed: 0 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -37,127 +37,6 @@ paths:
3737
$ref: "#/definitions/Info"
3838
security:
3939
- oauth2: []
40-
/api/v1/spaces/{spaceGuid}/files:
41-
get:
42-
summary: ""
43-
description: "Retrieves all Multi-Target Application files "
44-
operationId: "getMtaFiles"
45-
produces:
46-
- "application/json"
47-
parameters:
48-
- name: "spaceGuid"
49-
in: "path"
50-
description: "GUID of space with mtas"
51-
required: true
52-
type: "string"
53-
- name: "namespace"
54-
in: "query"
55-
description: "Filter mtas by namespace"
56-
required: false
57-
type: "string"
58-
responses:
59-
200:
60-
description: "OK"
61-
schema:
62-
type: "array"
63-
items:
64-
$ref: "#/definitions/FileMetadata"
65-
security:
66-
- oauth2: []
67-
post:
68-
summary: ""
69-
description: "Uploads a Multi Target Application archive or an Extension Descriptor "
70-
operationId: "uploadMtaFile"
71-
consumes:
72-
- "multipart/form-data"
73-
produces:
74-
- "application/json"
75-
parameters:
76-
- name: "spaceGuid"
77-
in: "path"
78-
description: "GUID of space you wish to deploy in"
79-
required: true
80-
type: "string"
81-
- name: "namespace"
82-
in: "query"
83-
description: "file namespace"
84-
required: false
85-
type: "string"
86-
responses:
87-
200:
88-
description: "successful operation"
89-
schema:
90-
$ref: "#/definitions/FileMetadata"
91-
201:
92-
description: "Created"
93-
schema:
94-
$ref: "#/definitions/FileMetadata"
95-
security:
96-
- oauth2: []
97-
/api/v1/spaces/{spaceGuid}/files/async:
98-
post:
99-
summary: ""
100-
description: "Uploads a Multi Target Application archive or an Extension Descriptor\
101-
\ from a remote endpoint"
102-
operationId: "startUploadFromUrl"
103-
consumes:
104-
- "application/json"
105-
parameters:
106-
- name: "spaceGuid"
107-
in: "path"
108-
description: "GUID of space you wish to deploy in"
109-
required: true
110-
type: "string"
111-
- name: "namespace"
112-
in: "query"
113-
description: "file namespace"
114-
required: false
115-
type: "string"
116-
- in: "body"
117-
name: "body"
118-
description: "URL reference to a remote file"
119-
required: false
120-
schema:
121-
$ref: "#/definitions/FileUrl"
122-
responses:
123-
202:
124-
description: "Accepted"
125-
security:
126-
- oauth2: []
127-
/api/v1/spaces/{spaceGuid}/files/jobs/{jobId}:
128-
get:
129-
summary: ""
130-
description: "Gets the status of an async upload job"
131-
operationId: "getAsyncUploadJob"
132-
produces:
133-
- "application/json"
134-
parameters:
135-
- name: "spaceGuid"
136-
in: "path"
137-
description: "GUID of space you wish to deploy in"
138-
required: true
139-
type: "string"
140-
- name: "namespace"
141-
in: "query"
142-
description: "file namespace"
143-
required: false
144-
type: "string"
145-
- name: "jobId"
146-
in: "path"
147-
description: "ID of the upload job"
148-
required: true
149-
type: "string"
150-
responses:
151-
200:
152-
description: "OK"
153-
schema:
154-
$ref: "#/definitions/AsyncUploadResult"
155-
201:
156-
description: "Created"
157-
schema:
158-
$ref: "#/definitions/AsyncUploadResult"
159-
security:
160-
- oauth2: []
16140
/api/v1/spaces/{spaceGuid}/mtas:
16241
get:
16342
summary: ""
@@ -403,66 +282,6 @@ securityDefinitions:
403282
flow: "password"
404283
scopes: {}
405284
definitions:
406-
AsyncUploadResult:
407-
type: "object"
408-
properties:
409-
status:
410-
type: "string"
411-
readOnly: true
412-
enum:
413-
- "RUNNING"
414-
- "FINISHED"
415-
- "ERROR"
416-
bytes_processed:
417-
type: "integer"
418-
format: "int64"
419-
readOnly: true
420-
error:
421-
type: "string"
422-
readOnly: true
423-
file:
424-
readOnly: true
425-
$ref: "#/definitions/FileMetadata"
426-
mta_id:
427-
type: "string"
428-
readOnly: true
429-
client_actions:
430-
type: "array"
431-
readOnly: true
432-
items:
433-
type: "string"
434-
enum:
435-
- "RETRY_UPLOAD"
436-
FileMetadata:
437-
type: "object"
438-
properties:
439-
id:
440-
type: "string"
441-
readOnly: true
442-
name:
443-
type: "string"
444-
readOnly: true
445-
size:
446-
type: "integer"
447-
readOnly: true
448-
digest:
449-
type: "string"
450-
readOnly: true
451-
digestAlgorithm:
452-
type: "string"
453-
readOnly: true
454-
space:
455-
type: "string"
456-
readOnly: true
457-
namespace:
458-
type: "string"
459-
readOnly: true
460-
FileUrl:
461-
type: "object"
462-
properties:
463-
file_url:
464-
type: "string"
465-
readOnly: true
466285
Info:
467286
type: "object"
468287
properties:

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/cf/detect/AppSuffixDeterminer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public AppSuffixDeterminer(boolean keepOriginalNamesAfterDeploy, boolean isAfter
1010
this.isAfterResumePhase = isAfterResumePhase;
1111
}
1212

13-
public boolean shouldAppendApplicationSuffix() {
13+
public boolean shouldAppendIdleSuffix() {
1414
return keepOriginalNamesAfterDeploy && isAfterResumePhase;
1515
}
1616
}

multiapps-controller-core/src/main/java/org/cloudfoundry/multiapps/controller/core/cf/v2/ApplicationCloudModelBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private DeployedMtaApplication findDeployedApplication(String moduleName, Deploy
152152

153153
private String getApplicationName(Module module) {
154154
String applicationName = NameUtil.getApplicationName(module);
155-
if (appSuffixDeterminer.shouldAppendApplicationSuffix()) {
155+
if (appSuffixDeterminer.shouldAppendIdleSuffix()) {
156156
applicationName += BlueGreenApplicationNameSuffix.IDLE.asSuffix();
157157
}
158158
return applicationName;

multiapps-controller-core/src/test/java/org/cloudfoundry/multiapps/controller/core/cf/detect/AppSuffixDeterminerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package org.cloudfoundry.multiapps.controller.core.cf.detect;
22

3-
import static org.junit.jupiter.api.Assertions.assertEquals;
4-
53
import java.util.stream.Stream;
64

75
import org.junit.jupiter.params.ParameterizedTest;
86
import org.junit.jupiter.params.provider.Arguments;
97
import org.junit.jupiter.params.provider.MethodSource;
108

9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
1111
class AppSuffixDeterminerTest {
1212

1313
static Stream<Arguments> testAppSuffixDeterminer() {
1414
return Stream.of(
15-
//@formatter:off
15+
//@formatter:off
1616
// (1) Keep original app names is not set and the process is not after resume phase
1717
Arguments.of(false, false, false),
1818
// (2) Keep original app names is set but the process is not after resume phase
@@ -29,6 +29,6 @@ static Stream<Arguments> testAppSuffixDeterminer() {
2929
@MethodSource
3030
void testAppSuffixDeterminer(boolean keepOriginalNamesAfterDeploy, boolean isAfterResumePhase, boolean shouldAppendApplicationSuffix) {
3131
AppSuffixDeterminer appSuffixDeterminer = new AppSuffixDeterminer(keepOriginalNamesAfterDeploy, isAfterResumePhase);
32-
assertEquals(shouldAppendApplicationSuffix, appSuffixDeterminer.shouldAppendApplicationSuffix());
32+
assertEquals(shouldAppendApplicationSuffix, appSuffixDeterminer.shouldAppendIdleSuffix());
3333
}
3434
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.cloudfoundry.multiapps.controller.client.facade.CloudControllerClient;
1919
import org.cloudfoundry.multiapps.controller.client.facade.CloudCredentials;
2020
import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudApplication;
21+
import org.cloudfoundry.multiapps.controller.client.facade.domain.ImmutableCloudApplication;
2122
import org.cloudfoundry.multiapps.controller.client.facade.domain.ImmutableStaging;
2223
import org.cloudfoundry.multiapps.controller.client.facade.domain.Staging;
2324
import org.cloudfoundry.multiapps.controller.client.facade.dto.ApplicationToCreateDto;
@@ -297,9 +298,9 @@ private UpdateStrategy getEnvUpdateStrategy() {
297298

298299
@Override
299300
public void handleApplicationName() {
300-
if (!context.getVariable(Variables.KEEP_ORIGINAL_APP_NAMES_AFTER_DEPLOY)) {
301-
getStepLogger().warn(
302-
Variables.KEEP_ORIGINAL_APP_NAMES_AFTER_DEPLOY + " is set to false. The application name will not be updated.");
301+
boolean processIsBlueGreenWithIdleSuffix = StepsUtil.getAppSuffixDeterminer(context)
302+
.shouldAppendIdleSuffix();
303+
if (!processIsBlueGreenWithIdleSuffix) {
303304
return;
304305
}
305306

@@ -309,13 +310,15 @@ public void handleApplicationName() {
309310
getStepLogger().info(Messages.THE_DETECTED_APPLICATION_HAS_THE_SAME_NAME_AS_THE_NEW_ONE);
310311
return;
311312
}
312-
getStepLogger().warn("Renaming application " + oldName + " to " + newName);
313+
313314
getStepLogger().info(Messages.RENAMING_APPLICATION_0_TO_1, oldName, newName);
314315
client.rename(oldName, newName);
316+
317+
context.setVariable(Variables.EXISTING_APP, ImmutableCloudApplication.copyOf(existingApp)
318+
.withName(newName));
315319
context.setVariable(Variables.APP_TO_PROCESS, ImmutableCloudApplicationExtended.copyOf(app)
316320
.withName(newName));
317321

318-
getStepLogger().warn("Updating application name in configuration subscriptions");
319322
updateConfigurationSubscribers(oldName, newName);
320323
}
321324

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected StepPhase executeStep(ProcessContext context) {
2525
int desiredInstances = app.getInstances();
2626
int currentInstances = 1; // default instances when creating an app
2727
if (existingApp != null) {
28-
currentInstances = client.getApplicationProcess(client.getApplicationGuid(app.getName()))
28+
currentInstances = client.getApplicationProcess(client.getApplicationGuid(existingApp.getName()))
2929
.getInstances();
3030
}
3131

multiapps-controller-process/src/test/java/org/cloudfoundry/multiapps/controller/process/steps/CreateOrUpdateStepWithExistingAppTest.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@
2828
import org.cloudfoundry.multiapps.controller.client.lib.domain.ImmutableCloudApplicationExtended;
2929
import org.cloudfoundry.multiapps.controller.core.Constants;
3030
import org.cloudfoundry.multiapps.controller.core.cf.clients.AppBoundServiceInstanceNamesGetter;
31+
import org.cloudfoundry.multiapps.controller.core.model.Phase;
3132
import org.cloudfoundry.multiapps.controller.core.util.ApplicationURI;
33+
import org.cloudfoundry.multiapps.controller.persistence.model.ConfigurationSubscription;
34+
import org.cloudfoundry.multiapps.controller.persistence.query.ConfigurationSubscriptionQuery;
35+
import org.cloudfoundry.multiapps.controller.persistence.services.ConfigurationSubscriptionService;
3236
import org.cloudfoundry.multiapps.controller.process.variables.Variables;
3337
import org.junit.jupiter.api.Test;
3438
import org.junit.jupiter.params.ParameterizedTest;
3539
import org.junit.jupiter.params.provider.Arguments;
3640
import org.junit.jupiter.params.provider.MethodSource;
41+
import org.mockito.Answers;
3742
import org.mockito.Mock;
3843

3944
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -59,6 +64,10 @@ class CreateOrUpdateStepWithExistingAppTest extends SyncFlowableStepTest<CreateO
5964

6065
@Mock
6166
private AppBoundServiceInstanceNamesGetter appServicesGetter;
67+
@Mock
68+
private ConfigurationSubscriptionService subscriptionService;
69+
@Mock(answer = Answers.RETURNS_SELF)
70+
private ConfigurationSubscriptionQuery query;
6271

6372
static Stream<Arguments> testHandleStagingApplicationAttributes() {
6473
return Stream.of(
@@ -217,7 +226,7 @@ private void prepareClient(CloudApplication application, Set<CloudRoute> routes,
217226
when(appServicesGetter.getServiceInstanceNamesBoundToApp(any())).thenReturn(services);
218227
when(client.getApplicationEnvironment(application.getGuid())).thenReturn(env);
219228
application = prepareAppWithStaging(application, staging);
220-
when(client.getApplication(APP_NAME, false)).thenReturn(application);
229+
when(client.getApplication(application.getName(), false)).thenReturn(application);
221230
when(client.getApplicationSshEnabled(application.getGuid())).thenReturn(staging.isSshEnabled() != null && staging.isSshEnabled());
222231
when(client.getApplicationRoutes(application.getGuid())).thenReturn(List.copyOf(routes));
223232
String command = staging.getCommand() == null ? DEFAULT_COMMAND : staging.getCommand();
@@ -471,6 +480,32 @@ private Map<String, String> buildExpectedEnvWithDeployAttributes(Map<String, Str
471480
return expectedEnvMap;
472481
}
473482

483+
@Test
484+
void testHandleApplicationName() {
485+
String idleAppName = APP_NAME + "-idle";
486+
487+
CloudApplication existingApplication = getApplicationBuilder(false).name(idleAppName)
488+
.build();
489+
CloudApplicationExtended application = getApplicationBuilder(false).name(idleAppName)
490+
.build();
491+
prepareContext(application, true);
492+
context.setVariable(Variables.KEEP_ORIGINAL_APP_NAMES_AFTER_DEPLOY, true);
493+
context.setVariable(Variables.PHASE, Phase.AFTER_RESUME);
494+
prepareClientWithServices(existingApplication, List.of());
495+
496+
when(query.list())
497+
.thenReturn(List.of(new ConfigurationSubscription(0, "", "", idleAppName, null, null, null, null, null)));
498+
when(subscriptionService.createQuery())
499+
.thenReturn(query);
500+
501+
step.execute(execution);
502+
503+
assertStepFinishedSuccessfully();
504+
verify(client).rename(idleAppName, APP_NAME);
505+
verify(subscriptionService)
506+
.update(any(), eq(new ConfigurationSubscription(0, "", "", APP_NAME, null, null, null, null, null)));
507+
}
508+
474509
@Override
475510
protected CreateOrUpdateAppStep createStep() {
476511
return new CreateOrUpdateAppStep() {

0 commit comments

Comments
 (0)