public DeploymentConfiguration build() { return new DeploymentConfiguration(this); } }
public Deployment build() { return new Deployment(this); } }
public DeploymentPort build() { return new DeploymentPort(this); }
@Override protected DeploymentUnit createDeploymentUnit() { return new DockerDeploymentUnit.Builder("wiremock","rodolpheche/wiremock") .withCpu(0.5) .withMem(512) .withHealthProbe(new HttpProbe.Builder() .withPort(WIREMOCK_PORT) .build()) .withPort(new DeploymentPort.Builder("wiremock-server",WIREMOCK_PORT) .build()) .build(); }
@Override protected DeploymentUnit createDeploymentUnit() { return new DockerDeploymentUnit.Builder("appium",APPUIM_IMAGE) .withCpu(1.5) .withMem(2048) .withHealthProbe(new HttpProbe.Builder() .withPath(SERVER_STATUS_PATH) .withPort(APPIUM_PORT) .build()) .withReadinessProbe(new HttpProbe.Builder() .withPath(SERVER_STATUS_PATH) .withPort(APPIUM_PORT) .build()) .withPort(new DeploymentPort.Builder("appium-server",APPIUM_PORT) .build()) .withPort(new DeploymentPort.Builder("vnc-server",VNC_PORT) .build()) .build(); }
@Override protected URL createObject(DeploymentEndpoints endpoints) { for(DeploymentEndpoints.Endpoint endpoint : endpoints.list()) { if(endpoint.getName().equals("nginx-server")) { String host = endpoint.getHost(); int port = endpoint.getPort(); try { return new URL(String.format("http://%s:%s", host, port)); } catch (MalformedURLException e) { return null; } } } return null; }
public T get() { if(object!=null) { return object; } // Deploy ephemeral unit and fetch deployment endpoints logger.info("Creating deployment unit"); DeploymentUnit deploymentUnit = createDeploymentUnit(); logger.info("Creating deployment"); deployment = new Deployment.Builder(deploymentUnit, deploymentContext.getDeploymentConfiguration()) .build(); // Do deploy! try { logger.info("Deploying deployment {}",deployment.getId()); endpoints = deploymentContext.getDeploymentHandler().deploy(deployment); logger.info("Deployment {} done",deployment.getId()); logger.info("Endpoints found for deployment {}: {}",deployment.getId(),endpoints); } catch(Exception e) { logger.error("Error while deploying {}",deployment.getId(),e); throw new DeploymentException(e); } // Create object using endpoints try { object = createObject(endpoints); return object; } catch (Exception e) { logger.error("Error while creating object for deployment {}",deployment.getId(),e); throw new RuntimeException(e); } }
public void destroy() { if(deployment==null) { logger.warn("Nothing to destroy..."); return; } try { logger.info("Destroying deployment {}",deployment.getId()); deploymentContext.getDeploymentHandler().destroy(deployment); logger.info("Deployment {} destroyed successfully",deployment.getId()); deployment=null; object=null; } catch (Exception e) { logger.error("Error while destroying deployment",e); throw new DeploymentException(e); } }
public DeploymentEndpoints getEndpoints(){ if(endpoints==null || endpoints.list().size()==0) logger.warn("No endpoints to return"); return this.endpoints; }
@Override protected boolean isConditionMet() { try { DeploymentStatus deploymentStatus = getDeploymentStatus(); logger.info("Deployment {} status: {} - desired status: {}",deployment.getId(),deploymentStatus,desiredStatus); return deploymentStatus.equals(desiredStatus); } catch(Exception e) { logger.warn("Unable to fetch deployment status"); return false; } }
@Override protected boolean isConditionMet() { try { DeploymentEndpoints.Endpoint endpoint = getDeploymentEndpoint(); if(endpoint!=null) { logger.info("Deployment {} endpoint: {}", deployment.getId(), endpoint); return true; } else { logger.info("Deployment {} endpoint not ready", deployment.getId()); return false; } } catch(Exception e) { logger.warn("Unable to fetch deployment endpoint"); return false; } }
@Override protected DeploymentUnit createDeploymentUnit() { DeploymentUnit.Builder builder = new DockerDeploymentUnit.Builder("nginx","nginx:1.9.4") .withCpu(0.5) .withMem(512) .withHealthProbe(new HttpProbe.Builder() .withPort(NGINX_PORT) .build()) .withPort(new DeploymentPort.Builder("nginx-server",NGINX_PORT) .build()); if(staticContentVolume!=null) { builder.withVolume(new VolumeMount("static-content","/usr/share/nginx/html"),staticContentVolume); } return builder.build(); }
@Override protected AndroidDriver createObject(DeploymentEndpoints endpoints) { URL remoteWebDriverUrl = null; for(DeploymentEndpoints.Endpoint endpoint : endpoints.list()) { if(endpoint.getName().equals("appium-server")) { String host = endpoint.getHost(); int port = endpoint.getPort(); try { remoteWebDriverUrl = new URL(String.format("http://%s:%s/%s", host, port, "/wd/hub")); logger.info("RemoteWebDriver URL {}",remoteWebDriverUrl); } catch (MalformedURLException e) { return null; } } } return new AndroidDriver(remoteWebDriverUrl,desiredCapabilities); }
@Override protected URL createObject(DeploymentEndpoints endpoints) { for(DeploymentEndpoints.Endpoint endpoint : endpoints.list()) { if(endpoint.getName().equals("wiremock-server")) { String host = endpoint.getHost(); int port = endpoint.getPort(); WireMock wireMock = new WireMock(host,port); wireMock.register(StubMapping.buildFrom(stubMapping)); try { return new URL(String.format("http://%s:%s", host, port)); } catch (MalformedURLException e) { return null; } } } return null; }