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 @@ -18,8 +18,11 @@
import org.slf4j.LoggerFactory;

import com.openshift.restclient.IClient;
import com.openshift.restclient.NotFoundException;
import com.openshift.restclient.OpenShiftException;
import com.openshift.restclient.ResourceKind;
import com.openshift.restclient.capability.resources.IDeployCapability;
import com.openshift.restclient.http.IHttpConstants;
import com.openshift.restclient.model.IDeploymentConfig;
import com.openshift.restclient.model.IReplicationController;

Expand Down Expand Up @@ -50,18 +53,27 @@ public String getName() {

@Override
public void deploy() {
final String deploymentName = getLatestDeploymentName();
LOG.debug("Attempting to deploy latest deployment for config '%s'. Loading deployment: '%s'", config.getName(), deploymentName);
IReplicationController deployment = client.get(ResourceKind.REPLICATION_CONTROLLER, deploymentName, config.getNamespace());
final String status = getStatusFor(deployment);
if(COMPLETED_STATES.contains(status)) {
int version = config.getLatestVersionNumber();
config.setLatestVersionNumber(++version);
client.update(config);
}else {
LOG.debug("Skipping deployment because deployment status '%s' for '%s' is not in %s", new Object [] {status, deploymentName, COMPLETED_STATES});
try {
final String deploymentName = getLatestDeploymentName();
LOG.debug("Attempting to deploy latest deployment for config '%s'. Loading deployment: '%s'", config.getName(), deploymentName);
IReplicationController deployment = client.get(ResourceKind.REPLICATION_CONTROLLER, deploymentName, config.getNamespace());
final String status = getStatusFor(deployment);
if(!COMPLETED_STATES.contains(status)) {
LOG.debug("Skipping deployment because deployment status '%s' for '%s' is not in %s", new Object [] {status, deploymentName, COMPLETED_STATES});
return;
}
}catch(OpenShiftException e) {
if(e.getStatus() == null || e.getStatus().getCode() != IHttpConstants.STATUS_NOT_FOUND) {
//swallow exception like cli
throw e;
}
}

//bumping as currently not supporting 'retry'
int version = config.getLatestVersionNumber();
config.setLatestVersionNumber(++version);
client.update(config);

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
import com.openshift.restclient.IClient;
import com.openshift.restclient.OpenShiftException;
import com.openshift.restclient.capability.resources.IDeployCapability;
import com.openshift.restclient.http.IHttpConstants;
import com.openshift.restclient.model.IDeploymentConfig;
import com.openshift.restclient.model.IReplicationController;
import com.openshift.restclient.model.IStatus;

@RunWith(MockitoJUnitRunner.class)
public class DeployCapabilityTest {
Expand Down Expand Up @@ -58,6 +60,14 @@ public void testThrowsErrorWhenUnableToFindLatestDeployment() {
when(client.get(anyString(), anyString(), anyString())).thenThrow(OpenShiftException.class);
whenDeploying();
}

@Test
public void testWhenLatestDeploymentNotFound() {
givenTheLatestDeploymentIsNotFound();
whenDeploying();
thenVersionShouldIncrease(config);
thenResourceShouldBeUpdated(client, config);
}

@Test
public void testConfigNotUpdatedWhenAlreadyInProgress() {
Expand Down Expand Up @@ -107,4 +117,11 @@ private void givenDeploymentStatusIs(String status) {
private void givenTheDeploymentIsRetrieved() {
when(client.get(anyString(),anyString(),anyString())).thenReturn(deployment);
}

private void givenTheLatestDeploymentIsNotFound() {
IStatus status = mock(IStatus.class);
when(status.getCode()).thenReturn(IHttpConstants.STATUS_NOT_FOUND);
OpenShiftException e = new OpenShiftException(new RuntimeException(), status, "");
when(client.get(anyString(),anyString(),anyString())).thenThrow(e);
}
}