diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5c44f0a..f7c80c0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,12 +19,12 @@ on: env: PROJECT: 'datasance-pot' IMAGE_NAME: 'agent' - POTCTL_VERSION: '1.0.0' + POTCTL_VERSION: '1.3.4' CONTROLLER_IMAGE: 'ghcr.io/datasance/controller:latest' jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 permissions: actions: write checks: write @@ -47,7 +47,7 @@ jobs: java-version: '17' distribution: 'temurin' # cache: 'gradle' - - uses: gradle/gradle-build-action@v2 + - uses: gradle/gradle-build-action@v3 with: gradle-version: 8.4 arguments: build copy @@ -69,9 +69,15 @@ jobs: echo "VERSION=${VERSION:1}-${{ github.run_number }}" >> "${GITHUB_OUTPUT}" fi + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Github Container Registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: "ghcr.io" username: ${{ github.actor }} @@ -83,6 +89,7 @@ jobs: id: build_push_ghcr with: file: Dockerfile + platforms: linux/amd64, linux/arm64 push: true tags: | ghcr.io/datasance/${{ env.IMAGE_NAME }}:${{ steps.tags.outputs.VERSION }} diff --git a/.gitignore b/.gitignore index 52b6c1e..8d4f776 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ iofog-agent-client/bin iofog-version-controller/bin .vscode bats-core -*.iml \ No newline at end of file +*.iml +Dockerfile-test \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 7e2524b..79a692f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -42,19 +42,130 @@ COPY . . RUN gradle build -x test --no-daemon RUN gradle copy -x test --no-daemon -FROM registry.access.redhat.com/ubi8/ubi-minimal:8.10 +FROM eclipse-temurin:17-jdk-ubi9-minimal AS jre-build +COPY --from=builder packaging/iofog-agent/usr ./usr + +# Extract and analyze dependencies for the iofog-agent JAR +RUN jar xf /usr/bin/iofog-agent.jar && \ + jdeps \ + --ignore-missing-deps \ + --print-module-deps \ + --multi-release 17 \ + --recursive \ + --class-path 'BOOT-INF/lib/*' \ + /usr/bin/iofog-agent.jar > iofog-agent.txt + +# Extract and analyze dependencies for the iofog-agentd JAR +RUN jar xf /usr/bin/iofog-agentd.jar && \ + jdeps \ + --ignore-missing-deps \ + --print-module-deps \ + --multi-release 17 \ + --recursive \ + --class-path 'BOOT-INF/lib/*' \ + /usr/bin/iofog-agentd.jar > iofog-agentd.txt + +# Extract and analyze dependencies for the iofog-agentvc JAR +RUN jar xf /usr/bin/iofog-agentvc.jar && \ + jdeps \ + --ignore-missing-deps \ + --print-module-deps \ + --multi-release 17 \ + --recursive \ + --class-path 'BOOT-INF/lib/*' \ + /usr/bin/iofog-agentvc.jar > iofog-agentvc.txt + +# Merge the dependency files, remove duplicates, and format properly +RUN cat iofog-agent.txt iofog-agentd.txt iofog-agentvc.txt | \ + sort | uniq | paste -sd "," - > modules.txt + +# Create a custom Java runtime +RUN $JAVA_HOME/bin/jlink \ + --add-modules $(cat modules.txt) \ + --strip-debug \ + --no-man-pages \ + --no-header-files \ + --compress=2 \ + --output /javaruntime + +# Base builder stage for dependencies using UBI Minimal +FROM registry.access.redhat.com/ubi9/ubi-minimal:latest AS ubi-dep + +# Install necessary dependencies RUN true && \ - microdnf install -y curl ca-certificates java-17-openjdk-headless sudo shadow-utils && \ + microdnf install -y ca-certificates shadow-utils gzip procps-ng && \ + microdnf reinstall -y tzdata && \ microdnf clean all && \ + rm -rf /var/cache/* && \ true -#RUN mkdir -p /etc/bash_completion.d/ -#RUN mkdir -p /etc/init.d/ -#RUN mkdir -p /etc/iofog-agent/ -#RUN mkdir -p /usr +RUN true && \ + useradd -r -U -s /usr/bin/nologin iofog-agent && \ + usermod -aG root,wheel iofog-agent && \ + true -RUN echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/java.security +# Final stage using UBI Micro +FROM registry.access.redhat.com/ubi9/ubi-micro:latest + +# Copy dependencies from the ubi-dep stage +COPY --from=ubi-dep /usr/share/zoneinfo /usr/share/zoneinfo +COPY --from=ubi-dep /usr/bin/curl /usr/bin/ +COPY --from=ubi-dep /usr/bin/grep /usr/bin/ +COPY --from=ubi-dep /usr/bin/gzip /usr/bin/ +COPY --from=ubi-dep /usr/bin/pgrep /usr/bin/ +COPY --from=ubi-dep /usr/bin/awk /usr/bin/ +COPY --from=ubi-dep /etc/ssl/certs/ca-bundle.crt /etc/ssl/certs/ + +# Copy required shared libraries for curl grep awk +COPY --from=ubi-dep /usr/lib64/libc.so.6 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libcom_err.so.2 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libcrypto.so.3 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libcurl.so.4 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libffi.so.8 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libgmp.so.10 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libgnutls.so.30 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libgssapi_krb5.so.2 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libpcre.so.1 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libhogweed.so.6 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libidn2.so.0 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libk5crypto.so.3 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libkeyutils.so.1 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libkrb5.so.3 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libkrb5support.so.0 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libnettle.so.8 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libnghttp2.so.14 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libp11-kit.so.0 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libresolv.so.2 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libssl.so.3 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libtasn1.so.6 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libunistring.so.2 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libz.so.1 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libzstd.so.1 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libm.so.6 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libmpfr.so.6 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libreadline.so.8 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libsigsegv.so.2 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libtinfo.so.6 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libprocps.so.8 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libsystemd.so.0 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/liblz4.so.1 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libcap.so.2 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libgcrypt.so.20 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/libgpg-error.so.0 /usr/lib64/ +COPY --from=ubi-dep /usr/lib64/liblzma.so.5 /usr/lib64/ +# COPY --from=ubi-dep /usr/lib64/libblkid.so.1 /usr/lib64/ + + +# Copy the iofog-agent user and related configurations +COPY --from=ubi-dep /etc/passwd /etc/passwd +COPY --from=ubi-dep /etc/group /etc/group +COPY --from=ubi-dep /etc/shadow /etc/shadow + + +ENV JAVA_HOME=/opt/java/openjdk +ENV PATH="${JAVA_HOME}/bin:${PATH}" +COPY --from=jre-build /javaruntime $JAVA_HOME COPY --from=builder packaging/iofog-agent/usr ./usr COPY --from=builder packaging/iofog-agent/etc/init.d /etc/init.d/ @@ -62,14 +173,12 @@ COPY --from=builder packaging/iofog-agent/etc/bash_completion.d /etc/bash_comple COPY --from=builder packaging/iofog-agent/etc/iofog-agent /etc/iofog-agent/ RUN true && \ - useradd -r -U -s /usr/bin/nologin iofog-agent && \ - usermod -aG root,wheel iofog-agent && \ mv /etc/iofog-agent/config_new.xml /etc/iofog-agent/config.xml && \ mv /etc/iofog-agent/config-development_new.xml /etc/iofog-agent/config-development.xml && \ mv /etc/iofog-agent/config-production_new.xml /etc/iofog-agent/config-production.xml && \ mv /etc/iofog-agent/config-switcher_new.xml /etc/iofog-agent/config-switcher.xml && \ mv /etc/iofog-agent/cert_new.crt /etc/iofog-agent/cert.crt && \ - /etc/iofog-agent/local-api && \ + # /etc/iofog-agent/local-api && \ mkdir -p /var/backups/iofog-agent && \ mkdir -p /var/log/iofog-agent && \ mkdir -p /var/lib/iofog-agent && \ @@ -91,4 +200,16 @@ RUN true && \ chown :iofog-agent /usr/bin/iofog-agent && \ true -CMD [ "java", "-jar", "/usr/bin/iofog-agentd.jar", "start" ] \ No newline at end of file +COPY entrypoint.sh /etc/iofog-agent/entrypoint.sh +RUN chmod +x /etc/iofog-agent/entrypoint.sh +ENV LANG=C.UTF-8 \ + LC_ALL=C.UTF-8 \ + TZ="Europe/Istanbul" \ + IOFOG_DAEMON=container + +COPY LICENSE /licenses/LICENSE +LABEL org.opencontainers.image.description=agent +LABEL org.opencontainers.image.source=https://github.com/datasance/agent +LABEL org.opencontainers.image.licenses=EPL2.0 + +CMD ["/etc/iofog-agent/entrypoint.sh"] diff --git a/Dockerfile-old b/Dockerfile-old new file mode 100644 index 0000000..7e2524b --- /dev/null +++ b/Dockerfile-old @@ -0,0 +1,94 @@ +FROM docker.io/library/ubuntu:22.04 AS builder + +RUN apt-get update && \ + apt-get install -y unzip apt-utils curl openjdk-17-jdk && \ + apt-get clean + +# 1- Define a constant with the version of gradle you want to install +ARG GRADLE_VERSION=8.4 + +# 2- Define the URL where gradle can be downloaded from +ARG GRADLE_BASE_URL=https://services.gradle.org/distributions + +# 3- Define the SHA key to validate the gradle download +# obtained from here https://gradle.org/release-checksums/ +ARG GRADLE_SHA=3e1af3ae886920c3ac87f7a91f816c0c7c436f276a6eefdb3da152100fef72ae + +# 4- Create the directories, download gradle, validate the download, install it, remove downloaded file and set links +RUN mkdir -p /usr/share/gradle /usr/share/gradle/ref \ + && echo "Downlaoding gradle hash" \ + && curl -fsSL -o /tmp/gradle.zip ${GRADLE_BASE_URL}/gradle-${GRADLE_VERSION}-bin.zip \ + \ + && echo "Checking download hash" \ + && echo "${GRADLE_SHA} /tmp/gradle.zip" | sha256sum -c - \ + \ + && echo "Unziping gradle" \ + && unzip -d /usr/share/gradle /tmp/gradle.zip \ + \ + && echo "Cleaning and setting links" \ + && rm -f /tmp/gradle.zip \ + && ln -s /usr/share/gradle/gradle-${GRADLE_VERSION} /usr/bin/gradle + +# 5- Define environmental variables required by gradle +ENV GRADLE_VERSION=8.4 +ENV GRADLE_HOME=/usr/bin/gradle +ENV GRADLE_USER_HOME=/cache +ENV PATH=$PATH:$GRADLE_HOME/bin + +VOLUME $GRADLE_USER_HOME + +COPY . . + +RUN gradle build -x test --no-daemon +RUN gradle copy -x test --no-daemon + +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.10 + +RUN true && \ + microdnf install -y curl ca-certificates java-17-openjdk-headless sudo shadow-utils && \ + microdnf clean all && \ + true + +#RUN mkdir -p /etc/bash_completion.d/ +#RUN mkdir -p /etc/init.d/ +#RUN mkdir -p /etc/iofog-agent/ +#RUN mkdir -p /usr + +RUN echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/java.security + +COPY --from=builder packaging/iofog-agent/usr ./usr +COPY --from=builder packaging/iofog-agent/etc/init.d /etc/init.d/ +COPY --from=builder packaging/iofog-agent/etc/bash_completion.d /etc/bash_completion.d/ +COPY --from=builder packaging/iofog-agent/etc/iofog-agent /etc/iofog-agent/ + +RUN true && \ + useradd -r -U -s /usr/bin/nologin iofog-agent && \ + usermod -aG root,wheel iofog-agent && \ + mv /etc/iofog-agent/config_new.xml /etc/iofog-agent/config.xml && \ + mv /etc/iofog-agent/config-development_new.xml /etc/iofog-agent/config-development.xml && \ + mv /etc/iofog-agent/config-production_new.xml /etc/iofog-agent/config-production.xml && \ + mv /etc/iofog-agent/config-switcher_new.xml /etc/iofog-agent/config-switcher.xml && \ + mv /etc/iofog-agent/cert_new.crt /etc/iofog-agent/cert.crt && \ + /etc/iofog-agent/local-api && \ + mkdir -p /var/backups/iofog-agent && \ + mkdir -p /var/log/iofog-agent && \ + mkdir -p /var/lib/iofog-agent && \ + mkdir -p /var/run/iofog-agent && \ + chown -R :iofog-agent /etc/iofog-agent && \ + chown -R :iofog-agent /var/log/iofog-agent && \ + chown -R :iofog-agent /var/lib/iofog-agent && \ + chown -R :iofog-agent /var/run/iofog-agent && \ + chown -R :iofog-agent /var/backups/iofog-agent && \ + chown -R :iofog-agent /usr/share/iofog-agent && \ + chmod 774 -R /etc/iofog-agent && \ + chmod 774 -R /var/log/iofog-agent && \ + chmod 774 -R /var/lib/iofog-agent && \ + chmod 774 -R /var/run/iofog-agent && \ + chmod 774 -R /var/backups/iofog-agent && \ + chmod 754 -R /usr/share/iofog-agent && \ + chmod 774 /etc/init.d/iofog-agent && \ + chmod 754 /usr/bin/iofog-agent && \ + chown :iofog-agent /usr/bin/iofog-agent && \ + true + +CMD [ "java", "-jar", "/usr/bin/iofog-agentd.jar", "start" ] \ No newline at end of file diff --git a/build.gradle b/build.gradle index aef5b1a..329c7a2 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { allprojects { group = 'org.eclipse' - version = '3.3.0' + version = '3.3.2' } subprojects { diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..93e1de3 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Generate a random local-api key at runtime +tr -dc A-Za-z0-9 /etc/iofog-agent/local-api + + +chown :iofog-agent /etc/iofog-agent/local-api +chmod 600 /etc/iofog-agent/local-api + +# Start the iofog-agent +exec java -jar /usr/bin/iofog-agentd.jar start diff --git a/iofog-agent-client/src/main/java/org/eclipse/iofog/Client.java b/iofog-agent-client/src/main/java/org/eclipse/iofog/Client.java index dc034a2..36fd662 100644 --- a/iofog-agent-client/src/main/java/org/eclipse/iofog/Client.java +++ b/iofog-agent-client/src/main/java/org/eclipse/iofog/Client.java @@ -216,14 +216,15 @@ private static String showHelp() { " -ft Use auto to detect fog type by system commands,\n" + " use arm or intel_amd to set it manually\n" + + " -pf <#hours> Set the docker pruning frequency.\n" + " -sec Set the secure mode without using ssl \\n" + " certificates. \\n" + " -dev Set the developer's mode\\n" + "\n" + "\n" + - "Report bugs to: edgemaster@iofog.org\n" + - "ioFog home page: http://iofog.org\n" + - "For users with Eclipse accounts, report bugs to: https://bugs.eclipse.org/bugs/enter_bug.cgi?product=iofog"); + "Report bugs to: developer@datasance.com\n" + + "Datasance PoT docs: https://docs.datasance.com\n" + + "For users with GitHub accounts, report bugs to: https://github.com/Datasance/Agent/issues"); } private static String version() { diff --git a/iofog-agent-daemon/build.gradle b/iofog-agent-daemon/build.gradle index 79e7704..c42c8f0 100644 --- a/iofog-agent-daemon/build.gradle +++ b/iofog-agent-daemon/build.gradle @@ -23,7 +23,7 @@ dependencies { //testCompile 'org.powermock:powermock-module-junit4:2.0.2' //testCompile 'org.powermock:powermock-api-mockito2:2.0.2' //testCompile 'org.powermock:powermock-core:2.0.2' - implementation 'com.github.docker-java:docker-java:3.4.0' + implementation 'com.github.docker-java:docker-java:3.4.1' implementation 'io.netty:netty-all:4.1.113.Final' implementation 'org.jboss.logmanager:jboss-logmanager:3.0.6.Final' implementation 'com.github.mwiede:jsch:0.2.20' diff --git a/iofog-agent-daemon/src/main/java/org/eclipse/iofog/command_line/CommandLineAction.java b/iofog-agent-daemon/src/main/java/org/eclipse/iofog/command_line/CommandLineAction.java index ce4b3fc..cb7a8b2 100644 --- a/iofog-agent-daemon/src/main/java/org/eclipse/iofog/command_line/CommandLineAction.java +++ b/iofog-agent-daemon/src/main/java/org/eclipse/iofog/command_line/CommandLineAction.java @@ -387,15 +387,16 @@ private static String showHelp() { " -ft Use auto to detect fog type by system commands,\\n" + " use arm or intel_amd to set it manually\\n" + + " -pf <#hours> Set the docker pruning frequency.\n" + " -sec Set the secure mode without using ssl \\n" + " certificates. \\n" + " -dev Set the developer's mode\\n" + " -tz Set the device timeZone\\n" + "\\n" + "\\n" + - "Report bugs to: edgemaster@iofog.org\\n" + - "ioFog home page: http://iofog.org\\n" + - "For users with Eclipse accounts, report bugs to: https://bugs.eclipse.org/bugs/enter_bug.cgi?product=iofog"); + "Report bugs to: developer@datasance.com\\n" + + "Datasance PoT docs: https://docs.datasance.com\\n" + + "For users with GitHub accounts, report bugs to: https://github.com/Datasance/Agent/issues"); } } \ No newline at end of file diff --git a/iofog-agent-daemon/src/main/java/org/eclipse/iofog/field_agent/FieldAgent.java b/iofog-agent-daemon/src/main/java/org/eclipse/iofog/field_agent/FieldAgent.java index b99e558..dc20b69 100644 --- a/iofog-agent-daemon/src/main/java/org/eclipse/iofog/field_agent/FieldAgent.java +++ b/iofog-agent-daemon/src/main/java/org/eclipse/iofog/field_agent/FieldAgent.java @@ -362,7 +362,7 @@ private final Future processChanges(JsonObject changes) { try { DockerPruningManager.getInstance().pruneAgent(); } catch (Exception e) { - logError("Unable to update registries", e); + logError("Unable to prune Agent", e); resetChanges = false; } } @@ -665,7 +665,7 @@ private void deleteNode() { logError("Can't send delete node command", new AgentSystemException("Can't send delete node command", e)); } - deProvision(false); + deProvision(true); logDebug("Finish deleting current fog node from controller and make it deprovision"); } @@ -679,6 +679,12 @@ private void reboot() { return; // TODO implement } + String ioFogDaemon = System.getenv("IOFOG_DAEMON"); + if ("container".equals(ioFogDaemon)) { + logWarning("Skipping reboot as iofog-agent running inside container"); + return; // TODO implement + } + CommandShellResultSet, List> result = CommandShellExecutor.executeCommand("shutdown -r now"); if (result == null) { LoggingService.logError(MODULE_NAME, "Error in Remote reboot of Linux machine from IOFog controller", @@ -1129,7 +1135,7 @@ private void saveFile(JsonArray data, String filename) { String checksum = checksum(data.toString()); JsonObject object = Json.createObjectBuilder() .add("checksum", checksum) - .add("timestamp", lastGetChangesList) + .add("timestamp", System.currentTimeMillis()) .add("data", data) .build(); try (JsonWriter writer = Json.createWriter(new OutputStreamWriter(new FileOutputStream(filename), UTF_8))) { diff --git a/iofog-agent-daemon/src/main/java/org/eclipse/iofog/field_agent/VersionHandler.java b/iofog-agent-daemon/src/main/java/org/eclipse/iofog/field_agent/VersionHandler.java index 37ed2a4..d357463 100755 --- a/iofog-agent-daemon/src/main/java/org/eclipse/iofog/field_agent/VersionHandler.java +++ b/iofog-agent-daemon/src/main/java/org/eclipse/iofog/field_agent/VersionHandler.java @@ -67,8 +67,7 @@ public class VersionHandler { GET_IOFOG_PACKAGE_CANDIDATE_VERSION = "dnf --showduplicates list " + PACKAGE_NAME + DEV + " | grep iofog | awk '{print $2}' | sed -n \\$p\\"; UPDATE_PACKAGE_REPOSITORY = "dnf update -y"; GET_PACKAGE_MANAGER_LOCK_FILE_CONTENT = "cat /var/cache/dnf/metadata_lock.pid"; - } else if (distrName.contains("red hat") - || distrName.contains("centos") + } else if (distrName.contains("centos") || distrName.contains("amazon")) { GET_IOFOG_PACKAGE_DEV_VERSION = "(yum --showduplicates list installed " + PACKAGE_NAME + "-dev && yum --showduplicates list installed " + PACKAGE_NAME + ") | grep iofog | awk '{print $1}' | sed -e 's/iofog-agent\\(.*\\).noarch/\\1/')"; DEV = getIofogPackageDevVersion(); @@ -76,13 +75,23 @@ public class VersionHandler { GET_IOFOG_PACKAGE_CANDIDATE_VERSION = "yum --showduplicates list | grep " + PACKAGE_NAME + DEV + "| awk '{print $2}' | sed -n \\$p\\"; UPDATE_PACKAGE_REPOSITORY = "yum update -y"; GET_PACKAGE_MANAGER_LOCK_FILE_CONTENT = "cat /var/run/yum.pid"; - } else { + } else if (distrName.equalsIgnoreCase("container")) { + GET_IOFOG_PACKAGE_INSTALLED_VERSION = "iofog-agent version | grep -oP 'ioFog \\K[0-9]+\\.[0-9]+\\.[0-9]+'"; + GET_IOFOG_PACKAGE_CANDIDATE_VERSION = "curl -s https://api.github.com/repos/Datasance/Agent/releases | grep '\"tag_name\":' | grep -v '\"latest\"' | awk -F '\"' '{print $4}' | awk '{print substr($0, 2)}' | head -n 1"; + }else { logWarning(MODULE_NAME, "it looks like your distribution is not supported"); } } } private static String getDistributionName() { + // Check if IOFOG_DAEMON is set to "container" + String ioFogDaemon = System.getenv("IOFOG_DAEMON"); + if ("container".equals(ioFogDaemon)) { + return "container"; + } + + // Execute the command if IOFOG_DAEMON is not set to "container" CommandShellResultSet, List> resultSet = CommandShellExecutor.executeCommand(GET_LINUX_DISTRIBUTION_NAME); return resultSet.getValue().size() > 0 ? resultSet.getValue().get(0) : EMPTY; } @@ -130,24 +139,32 @@ private static String parseVersionResult(CommandShellResultSet, Lis */ static void changeVersion(JsonObject actionData) { LoggingService.logInfo(MODULE_NAME, "Start performing change version operation, received from ioFog controller"); + + // Check if the environment is running inside a container + String ioFogDaemon = System.getenv("IOFOG_DAEMON"); + if ("container".equalsIgnoreCase(ioFogDaemon)) { + LoggingService.logWarning(MODULE_NAME, "IoFog Agent daemon is running inside container, please upgrade/rollback version via `potctl`"); + return; // Return without changing version + } + if (SystemUtils.IS_OS_WINDOWS) { return; // TODO implement } - - try{ - + + try { VersionCommand versionCommand = parseJson(actionData); String provisionKey = actionData.getString("provisionKey"); - + if (isValidChangeVersionOperation(versionCommand)) { executeChangeVersionScript(versionCommand, provisionKey); } - + } catch (UnknownVersionCommandException e) { logError(MODULE_NAME, "Error performing change version operation : Invalid command", e); - } catch (Exception e){ + } catch (Exception e) { logError(MODULE_NAME, "Error performing change version operation", new AgentSystemException(e.getMessage(), e)); } + LoggingService.logInfo(MODULE_NAME, "Finished performing change version operation, received from ioFog controller"); } @@ -182,13 +199,23 @@ private static boolean isValidChangeVersionOperation(VersionCommand command) { static boolean isReadyToUpgrade() { boolean isReadyToUpgrade = false; - try{ - LoggingService.logDebug(MODULE_NAME, "Checking is ready to upgrade"); - isReadyToUpgrade = isNotWindows() - && isPackageRepositoryUpdated() - && areNotVersionsSame(); - LoggingService.logDebug(MODULE_NAME, "Is ready to upgrade : " + isReadyToUpgrade); - } catch (Exception e){ + try { + LoggingService.logDebug(MODULE_NAME, "Checking if ready to upgrade"); + + String ioFogDaemon = System.getenv("IOFOG_DAEMON"); + + // If IOFOG_DAEMON is "container", only check if versions are not the same + if ("container".equalsIgnoreCase(ioFogDaemon)) { + isReadyToUpgrade = areNotVersionsSame(); + } else { + // If it's not "container", check all conditions + isReadyToUpgrade = isNotWindows() + && isPackageRepositoryUpdated() + && areNotVersionsSame(); + } + + LoggingService.logDebug(MODULE_NAME, "Is ready to upgrade: " + isReadyToUpgrade); + } catch (Exception e) { LoggingService.logError(MODULE_NAME, "Error getting is ready to upgrade", new AgentSystemException(e.getMessage(), e)); } return isReadyToUpgrade; diff --git a/iofog-agent-daemon/src/main/java/org/eclipse/iofog/message_bus/MessageBus.java b/iofog-agent-daemon/src/main/java/org/eclipse/iofog/message_bus/MessageBus.java index c7463f2..1445374 100644 --- a/iofog-agent-daemon/src/main/java/org/eclipse/iofog/message_bus/MessageBus.java +++ b/iofog-agent-daemon/src/main/java/org/eclipse/iofog/message_bus/MessageBus.java @@ -210,7 +210,9 @@ private void updatePublishersAndReceivers() throws Exception { } receivers.get(rec).close(); messageBusServer.removeConsumer(rec); - publishers.remove(rec); + // publishers.remove(rec); + receivers.remove(rec); + } for (String newReceiver: newReceivers) { diff --git a/iofog-agent-daemon/src/main/java/org/eclipse/iofog/process_manager/ContainerManager.java b/iofog-agent-daemon/src/main/java/org/eclipse/iofog/process_manager/ContainerManager.java index 90053e0..e698752 100644 --- a/iofog-agent-daemon/src/main/java/org/eclipse/iofog/process_manager/ContainerManager.java +++ b/iofog-agent-daemon/src/main/java/org/eclipse/iofog/process_manager/ContainerManager.java @@ -89,7 +89,7 @@ private void createContainer(Microservice microservice, boolean pullImage) throw Registry registry = getRegistry(microservice); if (!registry.getUrl().equals("from_cache") && pullImage){ try { - docker.pullImage(microservice.getImageName(), microservice.getMicroserviceUuid(), registry); + docker.pullImage(microservice.getImageName(), microservice.getMicroserviceUuid(), microservice.getPlatform(), registry); StatusReporter.setProcessManagerStatus().setMicroservicesStatePercentage(microservice.getMicroserviceUuid(), Constants.PERCENTAGE_COMPLETION); } catch (Exception e) { diff --git a/iofog-agent-daemon/src/main/java/org/eclipse/iofog/process_manager/DockerUtil.java b/iofog-agent-daemon/src/main/java/org/eclipse/iofog/process_manager/DockerUtil.java index cf271ec..644192e 100755 --- a/iofog-agent-daemon/src/main/java/org/eclipse/iofog/process_manager/DockerUtil.java +++ b/iofog-agent-daemon/src/main/java/org/eclipse/iofog/process_manager/DockerUtil.java @@ -275,6 +275,24 @@ public static String getIoFogContainerName(String microserviceUuid) { return Constants.IOFOG_DOCKER_CONTAINER_NAME_PREFIX + microserviceUuid; } + /** + * gets container image + * + * @param containerId + * @return container image + */ + + public String getInspectContainersImage(String containerId) { + try { + InspectContainerResponse inspectResponse = dockerClient.inspectContainerCmd(containerId).exec(); + return inspectResponse.getConfig().getImage(); + } catch (Exception e) { + logError(MODULE_NAME, "Error getting started time of container", + new AgentSystemException(e.getMessage(), e)); + } + return null; + } + /** * returns a {@link Container} if exists * @@ -529,9 +547,10 @@ public void removeImageById(String imageId) throws NotFoundException, NotModifie * * @param imageName - imageName of {@link Microservice} * @param registry - {@link Registry} where image is placed + * @param platform - platform of {@link Microservice} */ @SuppressWarnings("resource") - public void pullImage(String imageName, String microserviceUuid, Registry registry) throws AgentSystemException { + public void pullImage(String imageName, String microserviceUuid, String platform, Registry registry) throws AgentSystemException { LoggingService.logInfo(MODULE_NAME, String.format("pull image name \"%s\" ", imageName)); Map statuses = new HashMap(); String tag = null, image; @@ -556,6 +575,10 @@ public void pullImage(String imageName, String microserviceUuid, Registry regist .withPassword(registry.getPassword()) ); req.withTag(tag); + // Add platform if it's not null + if (platform != null) { + req.withPlatform(platform); + } PullImageResultCallback resultCallback = new PullImageResultCallback() { @Override public void onNext(PullResponseItem item) { diff --git a/iofog-agent-daemon/src/main/java/org/eclipse/iofog/process_manager/ProcessManager.java b/iofog-agent-daemon/src/main/java/org/eclipse/iofog/process_manager/ProcessManager.java index dca20e1..cff2913 100644 --- a/iofog-agent-daemon/src/main/java/org/eclipse/iofog/process_manager/ProcessManager.java +++ b/iofog-agent-daemon/src/main/java/org/eclipse/iofog/process_manager/ProcessManager.java @@ -248,10 +248,26 @@ public void deleteRemainingMicroservices() { for (String uuid : allMicroserviceUuids) { boolean isCurrentMicroserviceUuid = currentMicroserviceUuids.contains(uuid); boolean isLatestMicroserviceUuid = latestMicroserviceUuids.contains(uuid); - - if (isCurrentMicroserviceUuid && !isLatestMicroserviceUuid) { + + // Determine if the UUID corresponds to a system microservice + boolean isSystemMicroserviceUuid = false; + Optional containerOptional = docker.getContainer(uuid); + if (containerOptional.isPresent()) { + Container container = containerOptional.get(); + String containerId = container.getId(); // Get container ID + + // Get container image using the containerId + String containerImage = docker.getInspectContainersImage(containerId); + if (containerImage != null) { + isSystemMicroserviceUuid = containerImage.equals(System.getenv("IOFOG_AGENT_IMAGE")) || + containerImage.equals(System.getenv("IOFOG_CONTROLLER_IMAGE")); + } + } + + // Perform actions based on the calculated flags + if (isCurrentMicroserviceUuid && !isLatestMicroserviceUuid && !isSystemMicroserviceUuid) { oldAgentMicroserviceUuids.add(uuid); - } else if (!isCurrentMicroserviceUuid && !isLatestMicroserviceUuid) { + } else if (!isCurrentMicroserviceUuid && !isLatestMicroserviceUuid && !isSystemMicroserviceUuid) { String containerName = DockerUtil.getIoFogContainerName(uuid); Map labels = runningContainersLabels.get(containerName); if ((labels != null && labels.get("iofog-uuid") != "") || Configuration.isWatchdogEnabled()) { diff --git a/iofog-agent-daemon/src/main/java/org/eclipse/iofog/pruning/DockerPruningManager.java b/iofog-agent-daemon/src/main/java/org/eclipse/iofog/pruning/DockerPruningManager.java index 8e13a6b..c7e86db 100644 --- a/iofog-agent-daemon/src/main/java/org/eclipse/iofog/pruning/DockerPruningManager.java +++ b/iofog-agent-daemon/src/main/java/org/eclipse/iofog/pruning/DockerPruningManager.java @@ -26,6 +26,7 @@ import java.util.*; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -39,6 +40,7 @@ public class DockerPruningManager { private DockerUtil docker = DockerUtil.getInstance(); private static DockerPruningManager instance; + private ScheduledFuture futureTask; public static DockerPruningManager getInstance() { if (instance == null) { @@ -59,6 +61,7 @@ public void start() throws Exception { LoggingService.logInfo(MODULE_NAME, "Start docker pruning manager"); scheduler = Executors.newScheduledThreadPool(1); scheduler.scheduleAtFixedRate(triggerPruneOnThresholdBreach, 0, 30, TimeUnit.MINUTES); + futureTask = scheduler.scheduleAtFixedRate(triggerPruneOnFrequency, Configuration.getDockerPruningFrequency(), Configuration.getDockerPruningFrequency(), TimeUnit.HOURS); LoggingService.logInfo(MODULE_NAME, "Docker pruning manager started"); } @@ -88,6 +91,27 @@ public void start() throws Exception { } }; + /** + * Trigger prune on available disk is equal to or less than threshold + */ + private final Runnable triggerPruneOnFrequency = () -> { + if (!isPruning) { + try { + LoggingService.logInfo(MODULE_NAME, "Start docker pruning job"); + isPruning = true; + Set unwantedImages = getUnwantedImagesList(); + if (unwantedImages.size() > 0) { + removeImagesById(unwantedImages); + } + } catch (Exception e){ + LoggingService.logError(MODULE_NAME,"Error in docker Pruning on frequency interval", new AgentSystemException(e.getMessage(), e)); + } finally { + isPruning = false; + LoggingService.logInfo(MODULE_NAME, "Pruning of unwanted images as frequency interval finished"); + } + } + }; + /** * Gets list of unwanted docker images to be removed * @return list @@ -156,4 +180,15 @@ public String pruneAgent(){ return "\nFailure - not pruned."; } } + + /** + * This method will reschedule "docker pruning freq" with the new param time + */ + public void changePruningFreqInterval() { + if (futureTask != null) { + futureTask.cancel(true); + } + futureTask = scheduler.scheduleAtFixedRate(triggerPruneOnFrequency, Configuration.getDockerPruningFrequency() , Configuration.getDockerPruningFrequency(), TimeUnit.HOURS); + } + } diff --git a/iofog-agent-daemon/src/main/java/org/eclipse/iofog/utils/configuration/Configuration.java b/iofog-agent-daemon/src/main/java/org/eclipse/iofog/utils/configuration/Configuration.java index 3617900..901d698 100644 --- a/iofog-agent-daemon/src/main/java/org/eclipse/iofog/utils/configuration/Configuration.java +++ b/iofog-agent-daemon/src/main/java/org/eclipse/iofog/utils/configuration/Configuration.java @@ -24,6 +24,7 @@ import org.eclipse.iofog.message_bus.MessageBus; import org.eclipse.iofog.network.IOFogNetworkInterfaceManager; import org.eclipse.iofog.process_manager.ProcessManager; +import org.eclipse.iofog.pruning.DockerPruningManager; import org.eclipse.iofog.resource_consumption_manager.ResourceConsumptionManager; import org.eclipse.iofog.supervisor.Supervisor; import org.eclipse.iofog.utils.Constants; @@ -399,6 +400,7 @@ public static void saveConfigUpdates() throws Exception { FieldAgent.getInstance().instanceConfigUpdated(); ProcessManager.getInstance().instanceConfigUpdated(); ResourceConsumptionManager.getInstance().instanceConfigUpdated(); + DockerPruningManager.getInstance().changePruningFreqInterval(); MessageBus.getInstance().instanceConfigUpdated(); // LoggingService.instanceConfigUpdated(); diff --git a/iofog-agent-daemon/src/main/resources/cmd_messages.properties b/iofog-agent-daemon/src/main/resources/cmd_messages.properties index b0a8f10..d2029cf 100644 --- a/iofog-agent-daemon/src/main/resources/cmd_messages.properties +++ b/iofog-agent-daemon/src/main/resources/cmd_messages.properties @@ -1,4 +1,4 @@ -version_msg=ioFog %s \\nCopyright (C) 2023 Datasance Teknoloji A.S. \\nEclipse ioFog is provided under the Eclipse Public License 2.0 (EPL-2.0) \\nhttps://www.eclipse.org/legal/epl-v20.html +version_msg=ioFog Agent %s \\nCopyright (C) 2023 Datasance Teknoloji A.S. \\nEclipse ioFog is provided under the Eclipse Public License 2.0 (EPL-2.0) \\nhttps://www.eclipse.org/legal/epl-v20.html deprovision_msg=Deprovisioning from controller ... %s provision_msg=Provisioning with key "%s" ... Result: %s provision_common_error=\\nProvisioning failed diff --git a/iofog-agent-daemon/src/test/java/org/eclipse/iofog/command_line/CommandLineActionTest.java b/iofog-agent-daemon/src/test/java/org/eclipse/iofog/command_line/CommandLineActionTest.java index 9a53523..ce18ad1 100644 --- a/iofog-agent-daemon/src/test/java/org/eclipse/iofog/command_line/CommandLineActionTest.java +++ b/iofog-agent-daemon/src/test/java/org/eclipse/iofog/command_line/CommandLineActionTest.java @@ -79,7 +79,7 @@ public void setup() { .thenReturn(new HashMap<>()) .thenThrow(new Exception("item not found or defined more than once")); - Mockito.when(CmdProperties.getVersion()).thenReturn("3.3.0"); + Mockito.when(CmdProperties.getVersion()).thenReturn("3.3.2"); Mockito.when(CmdProperties.getVersionMessage()).thenReturn(version); Mockito.when(CmdProperties.getDeprovisionMessage()).thenReturn("Deprovisioning from controller ... %s"); Mockito.when(CmdProperties.getProvisionMessage()).thenReturn("Provisioning with key \"%s\" ... Result: %s"); @@ -350,7 +350,7 @@ private static boolean isEqual(List list1, List list2) { "0.00 MB\\nSystem Available Memory : " + "0.00 MB\\nSystem Total CPU : 0.00 %"; - private String version = "ioFog 1 \n" + + private String version = "ioFog Agent 3.3.2 \n" + "Copyright (c) 2023 Datasance Teknoloji A.S. \n" + "Eclipse ioFog is provided under the Eclipse Public License 2.0 (EPL-2.0) \n" + "https://www.eclipse.org/legal/epl-v20.html"; @@ -428,13 +428,14 @@ private static boolean isEqual(List list1, List list2) { " -ft Use auto to detect fog type by system commands,\\n" + " use arm or intel_amd to set it manually\\n" + + " -pf <#hours> Set the docker pruning frequency.\n" + " -sec Set the secure mode without using ssl \\n" + " certificates. \\n" + " -dev Set the developer's mode\\n" + " -tz Set the device timeZone\\n" + "\\n" + "\\n" + - "Report bugs to: edgemaster@iofog.org\\n" + - "ioFog home page: http://iofog.org\\n" + - "For users with Eclipse accounts, report bugs to: https://bugs.eclipse.org/bugs/enter_bug.cgi?product=iofog"; + "Report bugs to: developer@datasance.com\\n" + + "Datasance PoT docs: https://docs.datasance.com\\n" + + "For users with GitHub accounts, report bugs to: https://github.com/Datasance/Agent/issues"; } diff --git a/iofog-agent-daemon/src/test/java/org/eclipse/iofog/command_line/CommandLineParserTest.java b/iofog-agent-daemon/src/test/java/org/eclipse/iofog/command_line/CommandLineParserTest.java index 2e2a298..c53d0c3 100644 --- a/iofog-agent-daemon/src/test/java/org/eclipse/iofog/command_line/CommandLineParserTest.java +++ b/iofog-agent-daemon/src/test/java/org/eclipse/iofog/command_line/CommandLineParserTest.java @@ -131,13 +131,14 @@ public void testParse() { " -ft Use auto to detect fog type by system commands,\\n" + " use arm or intel_amd to set it manually\\n" + + " -pf <#hours> Set the docker pruning frequency.\n" + " -sec Set the secure mode without using ssl \\n" + " certificates. \\n" + " -dev Set the developer's mode\\n" + " -tz Set the device timeZone\\n" + "\\n" + "\\n" + - "Report bugs to: edgemaster@iofog.org\\n" + - "ioFog home page: http://iofog.org\\n" + - "For users with Eclipse accounts, report bugs to: https://bugs.eclipse.org/bugs/enter_bug.cgi?product=iofog"; + "Report bugs to: developer@datasance.com\\n" + + "Datasance PoT docs: https://docs.datasance.com\\n" + + "For users with GitHub accounts, report bugs to: https://github.com/Datasance/Agent/issues"; } \ No newline at end of file diff --git a/iofog-agent-daemon/src/test/java/org/eclipse/iofog/process_manager/ContainerManagerTest.java b/iofog-agent-daemon/src/test/java/org/eclipse/iofog/process_manager/ContainerManagerTest.java index 9366e9e..b6a3556 100644 --- a/iofog-agent-daemon/src/test/java/org/eclipse/iofog/process_manager/ContainerManagerTest.java +++ b/iofog-agent-daemon/src/test/java/org/eclipse/iofog/process_manager/ContainerManagerTest.java @@ -346,7 +346,7 @@ public void testExecuteWhenContainerTaskAddAndRegistriesArePresentWithURLFromCac Mockito.when(microserviceManager.getRegistry(anyInt())).thenReturn(registry); Mockito.when(registry.getUrl()).thenReturn("from_cache"); containerManager.execute(containerTask); - verify(dockerUtil, never()).pullImage(any(), any(), any()); + verify(dockerUtil, never()).pullImage(any(), any(), any(), any()); verify(dockerUtil).createContainer(any(), any()); verify(microservice).setRebuild(anyBoolean()); Mockito.verify(dockerUtil).getContainer(eq(microservice.getMicroserviceUuid())); @@ -372,7 +372,7 @@ public void testExecuteWhenContainerTaskAddAndRegistriesArePresentWithURL() { Mockito.when(microserviceManager.getRegistry(anyInt())).thenReturn(registry); Mockito.when(registry.getUrl()).thenReturn("url"); containerManager.execute(containerTask); - verify(dockerUtil).pullImage(any(), any(), any()); + verify(dockerUtil).pullImage(any(), any(), any(), any()); verify(dockerUtil).createContainer(any(), any()); verify(microservice).setRebuild(anyBoolean()); Mockito.verify(dockerUtil).getContainer(eq(microservice.getMicroserviceUuid())); @@ -398,7 +398,7 @@ public void throwsExceptionWhenDockerImagePullIsCalledExecuteWhenContainerTaskAd Mockito.when(containerTask.getMicroserviceUuid()).thenReturn("uuid"); Mockito.when(dockerUtil.getContainer(anyString())).thenReturn(optionalContainer); Mockito.when(dockerUtil.findLocalImage(anyString())).thenReturn(false); - Mockito.doThrow(mock(AgentSystemException.class)).when(dockerUtil).pullImage(any(), any(), any()); + Mockito.doThrow(mock(AgentSystemException.class)).when(dockerUtil).pullImage(any(), any(), any(), any()); Mockito.when(microserviceManager.getRegistry(anyInt())).thenReturn(registry); Mockito.when(registry.getUrl()).thenReturn("url"); assertThrows(NotFoundException.class, () -> containerManager.execute(containerTask)); @@ -424,11 +424,11 @@ public void testWhenDockerImagePullIsCalledExecuteWhenContainerTaskAdd() { Mockito.when(containerTask.getMicroserviceUuid()).thenReturn("uuid"); Mockito.when(dockerUtil.getContainer(anyString())).thenReturn(optionalContainer); Mockito.when(dockerUtil.findLocalImage(anyString())).thenReturn(true); - Mockito.doThrow(mock(AgentSystemException.class)).when(dockerUtil).pullImage(any(), any(), any()); + Mockito.doThrow(mock(AgentSystemException.class)).when(dockerUtil).pullImage(any(), any(), any(), any()); Mockito.when(microserviceManager.getRegistry(anyInt())).thenReturn(registry); Mockito.when(registry.getUrl()).thenReturn("url"); containerManager.execute(containerTask); - verify(dockerUtil).pullImage(any(), any(), any()); + verify(dockerUtil).pullImage(any(), any(), any(), any()); verify(dockerUtil).createContainer(any(), any()); verify(microservice).setRebuild(anyBoolean()); Mockito.verify(LoggingService.class); @@ -465,7 +465,7 @@ public void testExecuteWhenContainerTaskUpdate() { Mockito.when(microserviceManager.getRegistry(anyInt())).thenReturn(registry); Mockito.when(registry.getUrl()).thenReturn("url"); containerManager.execute(containerTask); - verify(dockerUtil).pullImage(any(), any(), any()); + verify(dockerUtil).pullImage(any(), any(), any(), any()); verify(dockerUtil).createContainer(any(), any()); verify(microservice).setRebuild(anyBoolean()); } catch (Exception e) { @@ -500,7 +500,7 @@ public void throwsNotFoundExceptionWhenStartContainerIsCalledInExecuteWhenContai Mockito.when(microserviceManager.getRegistry(anyInt())).thenReturn(registry); Mockito.when(registry.getUrl()).thenReturn("url"); containerManager.execute(containerTask); - verify(dockerUtil).pullImage(any(), any(), any()); + verify(dockerUtil).pullImage(any(), any(), any(), any()); verify(dockerUtil).createContainer(any(), any()); verify(microservice).setRebuild(anyBoolean()); Mockito.verify(LoggingService.class); diff --git a/iofog-agent-daemon/src/test/java/org/eclipse/iofog/process_manager/DockerUtilTest.java b/iofog-agent-daemon/src/test/java/org/eclipse/iofog/process_manager/DockerUtilTest.java index 684a7ab..6a966b7 100644 --- a/iofog-agent-daemon/src/test/java/org/eclipse/iofog/process_manager/DockerUtilTest.java +++ b/iofog-agent-daemon/src/test/java/org/eclipse/iofog/process_manager/DockerUtilTest.java @@ -89,6 +89,7 @@ public class DockerUtilTest { private ListContainersCmd listContainersCmd; private MicroserviceStatus microserviceStatus; private String containerID; + private String platform; private String imageID; private String ipAddress; private final String[] containerNames = {".iofog_containerName1",".iofog_containerName2"}; @@ -155,6 +156,7 @@ public void setUp() throws Exception { String bridgeName = "default_bridge"; containerID = "containerID"; imageID = "imageID"; + platform = "platform"; ipAddress = "ipAddress"; dockerBridgeMap.put("com.docker.network.bridge.default_bridge", bridgeName); @@ -192,6 +194,7 @@ public void setUp() throws Exception { Mockito.when(dockerClient.inspectImageCmd(anyString())).thenReturn(inspectImageCmd); Mockito.doAnswer((Answer) invocation -> null).when(inspectImageCmd).exec(); Mockito.when(pullImageCmd.withRegistry(anyString())).thenReturn(pullImageCmd); + Mockito.when(pullImageCmd.withPlatform(anyString())).thenReturn(pullImageCmd); Mockito.when(pullImageCmd.withTag(anyString())).thenReturn(pullImageCmd); Mockito.when(pullImageCmd.withAuthConfig(any())).thenReturn(pullImageCmd); Mockito.when(pullImageCmd.exec(any())).thenReturn(pullImageResultCallback); @@ -888,7 +891,7 @@ public void throwsNotFoundExceptionWhenRemoveImageById() { */ @Test public void testPullImageWhenRegistryIsNull() throws AgentSystemException { - assertThrows(AgentSystemException.class, () -> dockerUtil.pullImage(imageID, containerID,null)); + assertThrows(AgentSystemException.class, () -> dockerUtil.pullImage(imageID, containerID, null, null)); } /** @@ -901,9 +904,10 @@ public void testPullImageWhenRegistryIsNotNullAndPublic() { Mockito.when(registry.getUrl()).thenReturn("url"); Mockito.when(registry.getIsPublic()).thenReturn(true); imageID = "agent:1.3.0-beta"; - dockerUtil.pullImage(imageID, containerID, registry); + dockerUtil.pullImage(imageID, containerID, platform, registry); Mockito.verify(dockerClient).pullImageCmd(any()); Mockito.verify(pullImageCmd).withRegistry(any()); + Mockito.verify(pullImageCmd).withPlatform(any()); Mockito.verify(pullImageCmd).withTag(any()); Mockito.verify(pullImageCmd).exec(any()); } catch (AgentSystemException e) { @@ -926,10 +930,11 @@ public void testPullImageWhenRegistryIsNotPublic() { Mockito.when(registry.getIsPublic()).thenReturn(false); imageID = "agent:1.3.0-beta"; containerID ="id"; - dockerUtil.pullImage(imageID, containerID, registry); + dockerUtil.pullImage(imageID, containerID, platform, registry); Mockito.verify(dockerClient).pullImageCmd(any()); Mockito.verify(pullImageCmd, Mockito.never()).withRegistry(any()); Mockito.verify(pullImageCmd).withTag(any()); + Mockito.verify(pullImageCmd).withPlatform(any()); Mockito.verify(pullImageCmd).withAuthConfig(any()); Mockito.verify(pullImageCmd).exec(any()); } catch (AgentSystemException e) { @@ -949,7 +954,7 @@ public void throwsNotFoundExceptionPullImage() throws AgentSystemException { Mockito.when(registry.getUrl()).thenReturn("url"); Mockito.when(registry.getIsPublic()).thenReturn(true); imageID = "agent:1.3.0-beta"; - assertThrows(AgentSystemException.class, () -> dockerUtil.pullImage(imageID, containerID, registry)); + assertThrows(AgentSystemException.class, () -> dockerUtil.pullImage(imageID, containerID, platform, registry)); } /** @@ -963,7 +968,7 @@ public void throwsNotModifiedExceptionExceptionPullImage() { Mockito.when(registry.getUrl()).thenReturn("url"); Mockito.when(registry.getIsPublic()).thenReturn(true); imageID = "agent:1.3.0-beta"; - assertThrows(AgentSystemException.class, () -> dockerUtil.pullImage(imageID, containerID, registry)); + assertThrows(AgentSystemException.class, () -> dockerUtil.pullImage(imageID, containerID, platform, registry)); } /** diff --git a/iofog-agent-daemon/src/test/java/org/eclipse/iofog/utils/CmdPropertiesTest.java b/iofog-agent-daemon/src/test/java/org/eclipse/iofog/utils/CmdPropertiesTest.java index a996070..7e813cf 100644 --- a/iofog-agent-daemon/src/test/java/org/eclipse/iofog/utils/CmdPropertiesTest.java +++ b/iofog-agent-daemon/src/test/java/org/eclipse/iofog/utils/CmdPropertiesTest.java @@ -46,7 +46,7 @@ public void tearDown() throws Exception { //@Test //public void getVersionMessage() { - // assertEquals("ioFog 3.3.0 \nCopyright (c) 2023 Datasance Teknoloji A.S. \nEclipse ioFog is provided under the Eclipse Public License 2.0 (EPL-2.0) \nhttps://www.eclipse.org/legal/epl-v20.html", + // assertEquals("ioFog Agent 3.3.2 \nCopyright (c) 2023 Datasance Teknoloji A.S. \nEclipse ioFog is provided under the Eclipse Public License 2.0 (EPL-2.0) \nhttps://www.eclipse.org/legal/epl-v20.html", // CmdProperties.getVersionMessage()); //}