Class OpenShiftUtils

  • public class OpenShiftUtils
    extends Object
    • Constructor Detail

      • OpenShiftUtils

        public OpenShiftUtils()
    • Method Detail

      • initializeOpenShiftClient

        public static void initializeOpenShiftClient​(String serverUrl,
                                                     int maxConnections)
        Initializes an OpenShiftClient
        serverUrl - the optional URL of where the OpenShift cluster API server is running
        maxConnections - max connections
      • getOpenShiftClient

        public static io.fabric8.openshift.client.OpenShiftClient getOpenShiftClient()
      • getAuthenticatedOpenShiftClient

        public static io.fabric8.openshift.client.OpenShiftClient getAuthenticatedOpenShiftClient()
      • getInformerFactory

        public static io.fabric8.kubernetes.client.informers.SharedInformerFactory getInformerFactory()
      • shutdownOpenShiftClient

        public static void shutdownOpenShiftClient()
      • isPipelineStrategyBuildConfig

        public static boolean isPipelineStrategyBuildConfig​(io.fabric8.openshift.api.model.BuildConfig bc)
        Checks if a BuildConfig relates to a Jenkins build
        bc - the BuildConfig
        true if this is an OpenShift BuildConfig which should be mirrored to a Jenkins Job
      • isPipelineStrategyBuild

        public static boolean isPipelineStrategyBuild​(io.fabric8.openshift.api.model.Build b)
      • jenkinsJobName

        public static String jenkinsJobName​(io.fabric8.openshift.api.model.BuildConfig bc)
        Finds the Jenkins job name for the given BuildConfig.
        bc - the BuildConfig
        the jenkins job name for the given BuildConfig
      • jenkinsJobName

        public static String jenkinsJobName​(String namespace,
                                            String buildConfigName)
        Creates the Jenkins Job name for the given buildConfigName
        namespace - the namespace of the build
        buildConfigName - the name of the BuildConfig in in the namespace
        the jenkins job name for the given namespace and name
      • jenkinsJobFullName

        public static String jenkinsJobFullName​(io.fabric8.openshift.api.model.BuildConfig bc)
        Finds the full jenkins job path including folders for the given BuildConfig.
        bc - the BuildConfig
        the jenkins job name for the given BuildConfig
      • getFullNameParent

        public static ItemGroup getFullNameParent​(Jenkins activeJenkins,
                                                  String fullName,
                                                  String namespace)
        Returns the parent for the given item full name or default to the active jenkins if it does not exist
        activeJenkins - the active Jenkins instance
        fullName - the full name of the instance
        namespace - the namespace where the instance runs
        and ItemGroup representing the full parent
      • jenkinsJobDisplayName

        public static String jenkinsJobDisplayName​(io.fabric8.openshift.api.model.BuildConfig bc)
        Finds the Jenkins job display name for the given BuildConfig.
        bc - the BuildConfig
        the jenkins job display name for the given BuildConfig
      • jenkinsJobDisplayName

        public static String jenkinsJobDisplayName​(String namespace,
                                                   String buildConfigName)
        Creates the Jenkins Job display name for the given buildConfigName
        namespace - the namespace of the build
        buildConfigName - the name of the BuildConfig in in the namespace
        the jenkins job display name for the given namespace and name
      • getNamespaceOrUseDefault

        public static String[] getNamespaceOrUseDefault​(String[] configuredNamespaces,
                                                        io.fabric8.openshift.client.OpenShiftClient client)
        Gets the current namespace running Jenkins inside or returns a reasonable default
        configuredNamespaces - the optional configured namespace(s)
        client - the OpenShift client
        the default namespace using either the configuration value, the default namespace on the client or "default"
      • getExternalServiceUrl

        public static String getExternalServiceUrl​(io.fabric8.openshift.client.OpenShiftClient openShiftClient,
                                                   String defaultProtocolText,
                                                   String namespace,
                                                   String serviceName)
        Returns the public URL of the given service
        openShiftClient - the OpenShiftClient to use
        defaultProtocolText - the protocol text part of a URL such as http://
        namespace - the Kubernetes namespace
        serviceName - the service name
        the external URL of the service
      • getJenkinsURL

        public static String getJenkinsURL​(io.fabric8.openshift.client.OpenShiftClient openShiftClient,
                                           String namespace)
        Calculates the external URL to access Jenkins
        namespace - the namespace Jenkins is runing inside
        openShiftClient - the OpenShift client
        the external URL to access Jenkins
      • getNamespacefromPodInputs

        public static String getNamespacefromPodInputs()
      • updateGitSourceUrl

        public static void updateGitSourceUrl​(io.fabric8.openshift.api.model.BuildConfig buildConfig,
                                              String gitUrl,
                                              String ref)
        Lazily creates the GitSource if need be then updates the git URL
        buildConfig - the BuildConfig to update
        gitUrl - the URL to the git repo
        ref - the git ref (commit/branch/etc) for the build
      • updateOpenShiftBuildPhase

        public static void updateOpenShiftBuildPhase​(io.fabric8.openshift.api.model.Build build,
                                                     String phase)
      • buildConfigNameFromJenkinsJobName

        public static NamespaceName buildConfigNameFromJenkinsJobName​(String jobName,
                                                                      String namespace)
        Maps a Jenkins Job name to an ObjectShift BuildConfig name
        jobName - the job to associate to a BuildConfig name
        namespace - the default namespace that Jenkins is running inside
        the namespaced name for the BuildConfig
      • parseResourceVersion

        public static long parseResourceVersion​(io.fabric8.kubernetes.api.model.HasMetadata obj)
      • parseResourceVersion

        public static long parseResourceVersion​(String resourceVersion)
      • formatTimestamp

        public static String formatTimestamp​(long timestamp)
      • parseTimestamp

        public static long parseTimestamp​(String timestamp)
      • isResourceWithoutStateEqual

        public static boolean isResourceWithoutStateEqual​(io.fabric8.kubernetes.api.model.HasMetadata oldObj,
                                                          io.fabric8.kubernetes.api.model.HasMetadata newObj)
      • dumpWithoutRuntimeStateAsYaml

        public static String dumpWithoutRuntimeStateAsYaml​(io.fabric8.kubernetes.api.model.HasMetadata obj)
                                                    throws com.fasterxml.jackson.core.JsonProcessingException
      • isCancellable

        public static boolean isCancellable​(io.fabric8.openshift.api.model.BuildStatus buildStatus)
      • isNew

        public static boolean isNew​(io.fabric8.openshift.api.model.BuildStatus buildStatus)
      • isCancelled

        public static boolean isCancelled​(io.fabric8.openshift.api.model.BuildStatus status)
      • getLabel

        public static String getLabel​(io.fabric8.kubernetes.api.model.HasMetadata resource,
                                      String name)
      • getAnnotation

        public static String getAnnotation​(io.fabric8.kubernetes.api.model.HasMetadata resource,
                                           String name)
      • addAnnotation

        public static void addAnnotation​(io.fabric8.kubernetes.api.model.HasMetadata resource,
                                         String name,
                                         String value)
      • getNamespace

        public static String getNamespace​(io.fabric8.kubernetes.api.model.HasMetadata resource)
      • getName

        public static String getName​(io.fabric8.kubernetes.api.model.HasMetadata resource)
      • getOpenshiftClient

        protected static io.fabric8.openshift.client.OpenShiftClient getOpenshiftClient()