forked from eclipse-jkube/jkube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (jkube-kit) : Initial draft for JKube Actions Summary (eclipse-j…
…kube#1033) Signed-off-by: Rohan Kumar <rohaan@redhat.com>
- Loading branch information
1 parent
65d37bf
commit 74f3f40
Showing
25 changed files
with
573 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
268 changes: 268 additions & 0 deletions
268
jkube-kit/common/src/main/java/org/eclipse/jkube/kit/common/Summary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,268 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.kit.common; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Summary { | ||
private static final String DASHED_LINE = "-------------------------------"; | ||
private static Summary summaryInstance; | ||
private String buildStrategy; | ||
private String packagedFileLocation; | ||
private String generatorName; | ||
private String dockerFileUsed; | ||
private String targetImageName; | ||
private boolean successful; | ||
private String failureCause; | ||
private List<String> generatedResourceFiles; | ||
private String aggregateResourceFile; | ||
private String targetClusterUrl; | ||
private List<String> createdKubernetesResources; | ||
private List<String> updatedKubernetesResources; | ||
|
||
private List<String> deletedKubernetesResources; | ||
|
||
private String pushRegistry; | ||
private String pushRegistryUser; | ||
private String pushedImage; | ||
private String helmChartName; | ||
private String helmChartCompressedLocation; | ||
private String helmChartLocation; | ||
private String helmRepository; | ||
private boolean printed; | ||
|
||
private Summary() { } | ||
|
||
public static Summary getInstance() { | ||
if (summaryInstance == null) { | ||
summaryInstance = new Summary(); | ||
summaryInstance.printed = false; | ||
} | ||
return summaryInstance; | ||
} | ||
|
||
public void setBuildStrategy(String buildStrategy) { | ||
this.buildStrategy = buildStrategy; | ||
} | ||
|
||
public void setPackagedFileLocation(String packagedFileLocation) { | ||
this.packagedFileLocation = packagedFileLocation; | ||
} | ||
|
||
public void setGeneratorName(String generatorName) { | ||
this.generatorName = generatorName; | ||
} | ||
|
||
public void setDockerFileUsed(String dockerFileUsed) { | ||
this.dockerFileUsed = dockerFileUsed; | ||
} | ||
|
||
public void setTargetImageName(String targetImageName) { | ||
this.targetImageName = targetImageName; | ||
} | ||
|
||
public void setSuccessful(boolean successful) { | ||
this.successful = successful; | ||
} | ||
|
||
public void setFailureCause(String failureCause) { | ||
this.failureCause = failureCause; | ||
} | ||
|
||
public void setAggregateResourceFile(String aggregateResourceFile) { | ||
this.aggregateResourceFile = aggregateResourceFile; | ||
} | ||
|
||
public void addGeneratedResourceFile(String resourceFilePath) { | ||
if (this.generatedResourceFiles == null) { | ||
this.generatedResourceFiles = new ArrayList<>(); | ||
} | ||
this.generatedResourceFiles.add(resourceFilePath); | ||
} | ||
|
||
public void addCreatedKubernetesResource(String kubernetesResource) { | ||
if (this.createdKubernetesResources == null) { | ||
this.createdKubernetesResources = new ArrayList<>(); | ||
} | ||
this.createdKubernetesResources.add(kubernetesResource); | ||
} | ||
|
||
public void addDeletedKubernetesResource(String kubernetesResource) { | ||
if (this.deletedKubernetesResources == null) { | ||
this.deletedKubernetesResources = new ArrayList<>(); | ||
} | ||
this.deletedKubernetesResources.add(kubernetesResource); | ||
} | ||
|
||
public void setTargetClusterUrl(String clusterUrl) { | ||
this.targetClusterUrl = clusterUrl; | ||
} | ||
|
||
public void addUpdatedKubernetesResource(String kubernetesResource) { | ||
if (this.updatedKubernetesResources == null) { | ||
this.updatedKubernetesResources = new ArrayList<>(); | ||
} | ||
this.updatedKubernetesResources.add(kubernetesResource); | ||
} | ||
|
||
public void setPushRegistry(String pushRegistry) { | ||
this.pushRegistry = pushRegistry; | ||
} | ||
|
||
public void setPushRegistryUser(String pushRegistryUser) { | ||
this.pushRegistryUser = pushRegistryUser; | ||
} | ||
|
||
public void setPushedImage(String pushedImage) { | ||
this.pushedImage = pushedImage; | ||
} | ||
|
||
public void setHelmChartLocation(String helmChartLocation) { | ||
this.helmChartLocation = helmChartLocation; | ||
} | ||
|
||
public void setHelmChartCompressedLocation(String helmChartCompressedLocation) { | ||
this.helmChartCompressedLocation = helmChartCompressedLocation; | ||
} | ||
|
||
public void setHelmRepository(String helmRepository) { | ||
this.helmRepository = helmRepository; | ||
} | ||
|
||
public void setHelmChartName(String helmChartName) { | ||
this.helmChartName = helmChartName; | ||
} | ||
|
||
public synchronized void printSummary(KitLogger logger) { | ||
if (summaryInstance != null && !printed) { | ||
printBanner(logger); | ||
printBuildSummary(logger); | ||
printResourceSummary(logger); | ||
printApplySummary(logger); | ||
printUndeploySummary(logger); | ||
printPushSummary(logger); | ||
printHelmSummary(logger); | ||
printHelmPushSummary(logger); | ||
if (successful) { | ||
logSummary(logger, "SUCCESS"); | ||
} else { | ||
logSummary(logger, "FAILURE"); | ||
logSummary(logger, "Failure cause : " + failureCause); | ||
} | ||
logSummary(logger, DASHED_LINE); | ||
printed = true; | ||
} | ||
} | ||
|
||
public static void clear() { | ||
summaryInstance = null; | ||
} | ||
|
||
private void printBanner(KitLogger logger) { | ||
logSummary(logger, DASHED_LINE); | ||
logSummary(logger, " SUMMARY"); | ||
logSummary(logger, DASHED_LINE); | ||
logSummary(logger, " __ / / //_/ / / / _ )/ __/"); | ||
logSummary(logger, "/ // / ,< / /_/ / _ / _/ "); | ||
logSummary(logger, "\\___/_/|_|\\____/____/___/ \n"); | ||
} | ||
|
||
private void printBuildSummary(KitLogger logger) { | ||
if (buildStrategy != null) { | ||
logSummary(logger, "Build Strategy : " + buildStrategy); | ||
} | ||
if (packagedFileLocation != null) { | ||
logSummary(logger, "Packaged File Location : " + packagedFileLocation); | ||
} | ||
if (generatorName != null) { | ||
logSummary(logger, "Generator Name : " + generatorName); | ||
} | ||
if (dockerFileUsed != null) { | ||
logSummary(logger, "Dockerfile used : " + dockerFileUsed); | ||
} | ||
if (targetImageName != null) { | ||
logSummary(logger, "Target Image Name : " + targetImageName); | ||
} | ||
} | ||
|
||
private void printResourceSummary(KitLogger logger) { | ||
if (generatedResourceFiles != null && !generatedResourceFiles.isEmpty()) { | ||
logSummary(logger, "Generated Resource Files:\n"); | ||
logList(logger, "Individual :\n", generatedResourceFiles); | ||
logSummary(logger, "\n"); | ||
logSummary(logger, "Aggregate : " + aggregateResourceFile); | ||
} | ||
} | ||
|
||
private void printApplySummary(KitLogger logger) { | ||
if (targetClusterUrl != null) { | ||
logSummary(logger, "Cluster URL : " + targetClusterUrl); | ||
} | ||
if (createdKubernetesResources != null && !createdKubernetesResources.isEmpty()) { | ||
logList(logger, "Created Resources: \n", createdKubernetesResources); | ||
} | ||
if (updatedKubernetesResources != null && !updatedKubernetesResources.isEmpty()) { | ||
logList(logger, "Updated Resources: \n", updatedKubernetesResources); | ||
} | ||
} | ||
|
||
private void printUndeploySummary(KitLogger logger) { | ||
if (deletedKubernetesResources != null && !deletedKubernetesResources.isEmpty()) { | ||
logList(logger, "Deleted Resources: \n", deletedKubernetesResources); | ||
} | ||
} | ||
|
||
|
||
private void printPushSummary(KitLogger logger) { | ||
if (pushRegistry!= null) { | ||
logSummary(logger, "Pushed to Image Registry: " + pushRegistry); | ||
} | ||
if (pushRegistryUser != null) { | ||
logSummary(logger, "Username : " + pushRegistryUser); | ||
} | ||
if (pushedImage != null) { | ||
logSummary(logger, "Pushed Image URL : " + pushedImage); | ||
} | ||
} | ||
|
||
private void printHelmSummary(KitLogger logger) { | ||
if (helmChartName != null) { | ||
logSummary(logger, "Helm Chart Name : " + helmChartName); | ||
} | ||
if (helmChartCompressedLocation != null) { | ||
logSummary(logger, "Helm Chart (Compressed) : " + helmChartCompressedLocation); | ||
} | ||
if (helmChartLocation != null) { | ||
logSummary(logger, "Helm Chart Directory : " + helmChartLocation); | ||
} | ||
} | ||
|
||
private void printHelmPushSummary(KitLogger logger) { | ||
if (helmRepository != null) { | ||
logSummary(logger, "Helm Repository : " + helmRepository); | ||
} | ||
} | ||
|
||
private void logList(KitLogger logger, String title, List<String> list) { | ||
logSummary(logger, title); | ||
for (String item : list) { | ||
logSummary(logger, " - " + item); | ||
} | ||
} | ||
|
||
private void logSummary(KitLogger logger, String message) { | ||
logger.info("[[C]] " + message + " [[C]]"); | ||
} | ||
} |
Oops, something went wrong.