Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into release/3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NehaNaithani committed Mar 29, 2022
2 parents 61a77ad + 0b94603 commit 256a541
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 256a541

Please sign in to comment.