Skip to content

Commit

Permalink
VBV-1860 - [Upgrade][HA] Application is not displayed after upgrade 7.3
Browse files Browse the repository at this point in the history
-> 7.4: missing tenant link

The problem was that in 7.2/7.3 when there is a failed provisioning from
the catalog it is possible to have an empty application in admiral. In
this case it is not possible to set tenant links to the application
because we set as tenant links the tenant links of the components.
- Added check if application does not have components during the
transformation of the data.

Change-Id: I7bf1d3e1f96c7d995ead98aa777618f7262ef914
Reviewed-on: https://bellevue-ci.eng.vmware.com:8080/29707
Upgrade-Verified: jenkins <[email protected]>
Closures-Verified: jenkins <[email protected]>
Bellevue-Verified: jenkins <[email protected]>
CS-Verified: jenkins <[email protected]>
Reviewed-by: Lazarin Lazarov <[email protected]>
  • Loading branch information
gmuleshkov committed Mar 26, 2018
1 parent adc972c commit 6e642f8
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.vmware.photon.controller.model.resources.ResourceState;
import com.vmware.xenon.common.Operation;
import com.vmware.xenon.common.OperationJoin;
import com.vmware.xenon.common.ServiceHost.ServiceNotFoundException;
import com.vmware.xenon.common.StatelessService;
import com.vmware.xenon.common.UriUtils;
import com.vmware.xenon.common.Utils;
Expand Down Expand Up @@ -77,23 +78,39 @@ private void processApplications(List<CompositeComponent> compositeComponents, O

private void processApplication(CompositeComponent state, Operation post) {
Set<String> tenantLinks = ConcurrentHashMap.newKeySet();
if (state.componentLinks == null || state.componentLinks.isEmpty()) {
logInfo("Composite component %s has no componentLinks. Tenant links will not be updated",
state.documentSelfLink);
if (compositeComponentsCount.decrementAndGet() == 0) {
logInfo("Composite components tranformation completed successfully");
post.complete();
}
return;
}
List<Operation> getOperations = state.componentLinks.stream()
.map(link -> Operation.createGet(getHost(), link)
.setReferer(getUri()))
.collect(Collectors.toList());

OperationJoin.create(getOperations).setCompletion((ops, ex) -> {
if (ex != null) {
post.fail(new Throwable(
"Error retrieving composite components: " + Utils.toString(ex),
ex.values().iterator().next()));
} else {
for (Operation op : ops.values()) {
ResourceState document = op.getBody(ResourceState.class);
for (Throwable t : ex.values()) {
if (!(t instanceof ServiceNotFoundException)) {
post.fail(new Throwable(
"Error retrieving composite components: " + Utils.toString(ex),
ex.values().iterator().next()));
return;
}
}
}

for (Operation op : ops.values()) {
ResourceState document = op.getBody(ResourceState.class);
if (document.tenantLinks != null) {
tenantLinks.addAll(new LinkedHashSet<String>(document.tenantLinks));
}
updateApplicationTenantLinks(state, tenantLinks, post);
}
updateApplicationTenantLinks(state, tenantLinks, post);
}).sendWith(getHost());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,64 @@ public void testThereShouldNotBeDuplicatedTenantLinks() throws Throwable {
Assert.assertTrue(application.tenantLinks.containsAll(volume.tenantLinks));
}

@Test
public void testApplicationWithoutComponentLinks() throws Throwable {
List<String> componentLinks = null;
CompositeComponent application = createCompositeComponent(componentLinks);
application.tenantLinks = new ArrayList<>();
application.tenantLinks.add("project1");
application.tenantLinks.add("project2");
application = doPost(application, CompositeComponentFactoryService.SELF_LINK);

doOperation(new ServiceDocument(),
UriUtils.buildUri(host, CompositeComponentsTransformationService.SELF_LINK), false,
Service.Action.POST);

application = getDocument(CompositeComponent.class, application.documentSelfLink);
Assert.assertTrue(application.tenantLinks.size() == 2);
}

@Test
public void testApplicationWithNonExistingComponents() throws Throwable {
List<String> tenantLinks = new ArrayList<String>();
tenantLinks.add("project1");
tenantLinks.add("project2");

// containerState1 does not exist
ContainerState containerState1 = createContainer(tenantLinks);
ContainerState containerState2 = createContainer(tenantLinks);
containerState2 = doPost(containerState2, ContainerFactoryService.SELF_LINK);

tenantLinks.add("project3");
ContainerNetworkState network = createNetwork(tenantLinks);
network = doPost(network, ContainerNetworkFactoryService.SELF_LINK);

ContainerVolumeState volume = createVolume(tenantLinks);
volume = doPost(volume, ContainerVolumeFactoryService.SELF_LINK);

List<String> componentLinks = new ArrayList<>();
componentLinks.add(containerState1.documentSelfLink);
componentLinks.add(containerState2.documentSelfLink);
componentLinks.add(network.documentSelfLink);
componentLinks.add(volume.documentSelfLink);
CompositeComponent application = createCompositeComponent(componentLinks);
application.tenantLinks = new ArrayList<>();
application.tenantLinks.add("project1");
application.tenantLinks.add("project2");
application = doPost(application, CompositeComponentFactoryService.SELF_LINK);

doOperation(new ServiceDocument(),
UriUtils.buildUri(host, CompositeComponentsTransformationService.SELF_LINK), false,
Service.Action.POST);

application = getDocument(CompositeComponent.class, application.documentSelfLink);
Assert.assertTrue(application.tenantLinks.size() == 3);
Assert.assertTrue(application.tenantLinks.containsAll(tenantLinks));
Assert.assertTrue(application.tenantLinks.containsAll(containerState1.tenantLinks));
Assert.assertTrue(application.tenantLinks.containsAll(network.tenantLinks));
Assert.assertTrue(application.tenantLinks.containsAll(volume.tenantLinks));
}

private CompositeComponent createCompositeComponent(List<String> componentLinks) {
CompositeComponent application = new CompositeComponent();
application.name = UUID.randomUUID().toString();
Expand Down

0 comments on commit 6e642f8

Please sign in to comment.