public KubernetesIaas(IaasProvider iaasProvider) { super(iaasProvider); partitionValidator = new KubernetesPartitionValidator(); payload = new ArrayList<NameValuePair>(); podActivationTimeout = Long.getLong("stratos.pod.activation.timeout"); if (podActivationTimeout == null) { podActivationTimeout = DEFAULT_POD_ACTIVATION_TIMEOUT; if (log.isInfoEnabled()) { log.info("Pod activation timeout was set: " + podActivationTimeout); } } }
private Pod waitForPodToBeActivated( MemberContext memberContext, KubernetesApiClient kubernetesApi) throws KubernetesClientException, InterruptedException { Pod pod; boolean podCreated = false; boolean podRunning = false; long startTime = System.currentTimeMillis(); while (!podRunning) { pod = kubernetesApi.getPod(memberContext.getKubernetesPodId()); if (pod != null) { podCreated = true; if (pod.getStatus().getPhase().equals(KubernetesConstants.POD_STATUS_RUNNING)) { log.info( String.format( "Pod status changed to running: [application] %s [cartridge] %s [member] %s " + "[pod] %s", memberContext.getApplicationId(), memberContext.getCartridgeType(), memberContext.getMemberId(), pod.getMetadata().getName())); return pod; } else { log.info( String.format( "Waiting pod status to be changed to running: [application] %s " + "[cartridge] %s [member] %s [pod] %s", memberContext.getApplicationId(), memberContext.getCartridgeType(), memberContext.getMemberId(), pod.getMetadata().getName())); } } else { log.info( String.format( "Waiting for pod to be created: [application] %s " + "[cartridge] %s [member] %s [pod] %s", memberContext.getApplicationId(), memberContext.getCartridgeType(), memberContext.getMemberId(), memberContext.getKubernetesPodId())); } if ((System.currentTimeMillis() - startTime) > podActivationTimeout) { break; } Thread.sleep(5000); } String message; if (podCreated) { // Pod created but status did not change to running message = String.format( "Pod status did not change to running within %d sec: " + "[application] %s [cartridge] %s [member] %s [pod] %s", (podActivationTimeout.intValue() / 1000), memberContext.getApplicationId(), memberContext.getCartridgeType(), memberContext.getMemberId(), memberContext.getKubernetesPodId()); log.error(message); } else { // Pod did not create message = String.format( "Pod did not create within %d sec: " + "[application] %s [cartridge] %s [member] %s [pod] %s", (podActivationTimeout.intValue() / 1000), memberContext.getApplicationId(), memberContext.getCartridgeType(), memberContext.getMemberId(), memberContext.getKubernetesPodId()); log.error(message); } throw new RuntimeException(message); }