Skip to content

Commit

Permalink
Microservice fails to deploy with FAILED [sc-12175] (#388)
Browse files Browse the repository at this point in the history
* Microservice fails to deploy with FAILED [sc-12175]

* Added the logic to retry getting ipAddress

* Updated connection timeout in orchestrator to 10s

* Added check if user has provided iofog extrahost then don't use system defined iofog:host

* Updated extrahost logic to check iofog keyword

* Removed unnecessary imports
  • Loading branch information
NehaNaithani authored Mar 29, 2022
1 parent 5467fa9 commit 0b94603
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@
import com.github.dockerjava.api.model.Image;
import org.eclipse.iofog.microservice.*;
import org.eclipse.iofog.exception.AgentSystemException;
import org.eclipse.iofog.network.IOFogNetworkInterface;
import org.eclipse.iofog.network.IOFogNetworkInterfaceManager;
import org.eclipse.iofog.status_reporter.StatusReporter;
import org.eclipse.iofog.utils.Constants;
import org.eclipse.iofog.utils.logging.LoggingService;

import java.util.Optional;

import java.util.concurrent.TimeUnit;
import static org.eclipse.iofog.microservice.Microservice.deleteLock;

/**
Expand Down Expand Up @@ -108,6 +106,10 @@ private void createContainer(Microservice microservice, boolean pullImage) throw
LoggingService.logInfo(MODULE_NAME, "Creating container \"" + microservice.getImageName() + "\"");
setMicroserviceStatus(microservice.getMicroserviceUuid(), MicroserviceState.STARTING);
String hostName = IOFogNetworkInterfaceManager.getInstance().getCurrentIpAddress();
if(hostName.isEmpty()){
hostName = retryHostName(hostName);
LoggingService.logInfo(MODULE_NAME, "hostname updated to \"" + hostName + "\"");
}
String id = docker.createContainer(microservice, hostName);
microservice.setContainerId(id);
microservice.setContainerIpAddress(docker.getContainerIpAddress(id));
Expand All @@ -117,6 +119,22 @@ private void createContainer(Microservice microservice, boolean pullImage) throw
setMicroserviceStatus(microservice.getMicroserviceUuid(), MicroserviceState.RUNNING);
}

private String retryHostName(String hostName) {
LoggingService.logDebug(MODULE_NAME, "Retrying to get hostname");
int tries = 0;
while (hostName.equals("") && tries < 5){
try {
TimeUnit.SECONDS.sleep(10);
IOFogNetworkInterfaceManager.getInstance().updateIOFogNetworkInterface();
hostName = IOFogNetworkInterfaceManager.getInstance().getCurrentIpAddress();
tries += 1;
} catch (Exception e) {
LoggingService.logError(MODULE_NAME, "Hostname not found", new AgentSystemException(e.getMessage(), e));
}
}
return hostName;
}

/**
* starts a {@link Container} and sets appropriate status
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,14 +655,22 @@ public String createContainer(Microservice microservice, String host) throws Not
});
}
String[] hosts;
boolean hasIoFogExtraHost = false;
List<String> extraHosts = microservice.getExtraHosts();
if (extraHosts != null && extraHosts.size() > 0) {
hosts = new String[extraHosts.size() + 1];
if (extraHosts.stream().filter(str -> str.trim().contains("iofog")).count() != 0) {
hasIoFogExtraHost = true;
hosts = new String[extraHosts.size()];
} else {
hosts = new String[extraHosts.size() + 1];
}
hosts = extraHosts.toArray(hosts);
} else {
hosts = new String[1];
}
hosts[hosts.length - 1] = "iofog:" + host;
if (!host.isEmpty() && !hasIoFogExtraHost) {
hosts[hosts.length - 1] = "iofog:" + host;
}

Map<String, String> containerLogConfig = new HashMap<>();
int logFiles = 1;
Expand Down Expand Up @@ -707,13 +715,13 @@ public String createContainer(Microservice microservice, String host) throws Not
if (SystemUtils.IS_OS_WINDOWS) {
if(microservice.isRootHostAccess()){
hostConfig.withNetworkMode("host").withExtraHosts(hosts).withPrivileged(true);
} else {
} else if(hosts[hosts.length - 1] != null) {
hostConfig.withExtraHosts(hosts).withPrivileged(true);
}
} else if (SystemUtils.IS_OS_LINUX || SystemUtils.IS_OS_MAC) {
if(microservice.isRootHostAccess()){
hostConfig.withNetworkMode("host").withPrivileged(true);
} else {
} else if(hosts[hosts.length - 1] != null) {
hostConfig.withExtraHosts(hosts).withPrivileged(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
* @author saeid
*/
public class Orchestrator {
private static final int CONNECTION_TIMEOUT = 5000;
private static final int CONNECTION_TIMEOUT = 10000;
private String controllerUrl;
private String iofogUuid;
private String iofogAccessToken;
Expand Down

0 comments on commit 0b94603

Please sign in to comment.