@Override public OpenShiftProvider asNewClone(final OpenShiftProvider source) { return new OpenShiftProviderImpl(source.getId(), (OpenShiftProviderConfig) source.getConfig()); } }
@Override public String toString() { return "OpenShiftRuntime{" + getId() + "}"; } }
@JsonIgnore public static OpenShiftProviderType instance() { if (instance == null) { instance = new OpenShiftProviderType(); } return instance; } }
@Override protected String getProviderTypeName() { return OpenShiftProviderType.instance().getProviderTypeName(); }
@Override public OpenShiftRuntime getValue() { OpenShiftProvider providerId = createOpenShiftProvider(); OpenShiftRuntimeConfig runtimeConfig = new ContextAwareOpenShiftRuntimeExecConfig( RUNTIME_NAME, providerId, APPLICATION_NAME, KIE_SERVER_CONTAINER_DEPLOYMENT, PROJECT_NAME, RESOURCE_SECRETS_URI, RESOURCE_STREAMS_URI, RESOURCE_TEMPLATE_NAME, RESOURCE_TEMPLATE_PARAM_DELIMITER, RESOURCE_TEMPLATE_PARAM_ASSIGNER, RESOURCE_TEMPLATE_PARAM_VALUES, RESOURCE_TEMPLATE_URI, SERVICE_NAME); return new OpenShiftRuntime(RUNTIME_ID, RUNTIME_NAME, runtimeConfig, providerId, new OpenShiftRuntimeEndpoint(PROTOCOL, HOST, PORT, CONTEXT), new OpenShiftRuntimeInfo(runtimeConfig), new OpenShiftRuntimeState(STATE, STARTED_AT)); } }
@Override public void refresh(RuntimeId runtimeId) throws RuntimeOperationException { OpenShiftRuntime runtime = (OpenShiftRuntime) runtimeRegistry.getRuntimeById(runtimeId.getId()); if (runtime != null) { try { //LOG.info( "Refreshing runtime: " + runtimeId.getId() ); OpenShiftRuntimeState runtimeState = openshift.getOpenShiftClient(runtime.getProviderId()).getRuntimeState(runtime.getId()); OpenShiftRuntime newRuntime = new OpenShiftRuntime(runtime.getId(), runtime.getName(), runtime.getConfig(), runtime.getProviderId(), runtime.getEndpoint(), runtime.getInfo(), runtimeState); runtimeRegistry.registerRuntime(newRuntime); } catch (OpenShiftClientException ex) { LOG.error("Error Refreshing runtime: " + runtimeId.getId(), ex); throw new RuntimeOperationException("Error Refreshing runtime: " + runtimeId.getId(), ex); } } }
private Optional<OpenShiftRuntime> create(final OpenShiftRuntimeConfig runtimeConfig) throws ProvisioningException { final Optional<OpenShiftProvider> _openshiftProvider = runtimeRegistry.getProvider(runtimeConfig.getProviderId(), OpenShiftProvider.class); if (!_openshiftProvider.isPresent()) { return Optional.empty(); } OpenShiftProvider openshiftProvider = _openshiftProvider.get(); OpenShiftClient openshiftClient = openshift.getOpenShiftClient(openshiftProvider); LOG.info("Creating runtime..."); OpenShiftRuntimeState runtimeState; try { runtimeState = openshiftClient.create(runtimeConfig); } catch (OpenShiftClientException ex) { throw new ProvisioningException(ex.getMessage(), ex); } final String id = runtimeConfig.getRuntimeId().toString(); LOG.info("Created runtime: " + id); OpenShiftRuntimeEndpoint endpoint = openshiftClient.getRuntimeEndpoint(id); return Optional.of(new OpenShiftRuntime(id, buildRuntimeName(runtimeConfig, id), runtimeConfig, openshiftProvider, endpoint, new OpenShiftRuntimeInfo(runtimeConfig), runtimeState)); }
public OpenShiftProviderImpl(final String id, final OpenShiftProviderConfig config) { super(id, OpenShiftProviderType.instance(), new OpenShiftProviderConfigImpl(config)); }
public static OpenShiftProviderImpl createOpenShiftProvider() { return new OpenShiftProviderImpl(PROVIDER_ID, new OpenShiftProviderConfigImpl().clear()); } }
@Override public void stop(RuntimeId runtimeId) throws RuntimeOperationException { OpenShiftRuntime runtime = (OpenShiftRuntime) runtimeRegistry.getRuntimeById(runtimeId.getId()); try { LOG.info("Stopping runtime: " + runtimeId.getId()); openshift.getOpenShiftClient(runtime.getProviderId()).stop(runtime.getId()); refresh(runtimeId); LOG.info("Stopped runtime: " + runtimeId.getId()); } catch (OpenShiftClientException ex) { LOG.error("Error Stopping runtime: " + runtimeId.getId(), ex); throw new RuntimeOperationException("Error Stopping runtime: " + runtimeId.getId(), ex); } }
@Override public OpenShiftClient getOpenShiftClient(final ProviderId providerId) { if (!clientMap.containsKey(providerId.getId())) { checkInstanceOf("providerId", providerId, OpenShiftProvider.class); ProviderConfig providerConfig = ((OpenShiftProvider) providerId).getConfig(); OpenShiftClient client = newOpenShiftClient(providerConfig); clientMap.put(providerId.getId(), client); } return clientMap.get(providerId.getId()); }
@Override protected String getProviderTypeName() { return OpenShiftProviderType.instance().getProviderTypeName(); }
@Override public OpenShiftRuntime getValue() { OpenShiftProvider providerId = createOpenShiftProvider(); OpenShiftRuntimeConfig runtimeConfig = new ContextAwareOpenShiftRuntimeExecConfig( RUNTIME_NAME, providerId, APPLICATION_NAME, KIE_SERVER_CONTAINER_DEPLOYMENT, PROJECT_NAME, RESOURCE_SECRETS_URI, RESOURCE_STREAMS_URI, RESOURCE_TEMPLATE_NAME, RESOURCE_TEMPLATE_PARAM_DELIMITER, RESOURCE_TEMPLATE_PARAM_ASSIGNER, RESOURCE_TEMPLATE_PARAM_VALUES, RESOURCE_TEMPLATE_URI, SERVICE_NAME); return new OpenShiftRuntime(RUNTIME_ID, RUNTIME_NAME, runtimeConfig, providerId, new OpenShiftRuntimeEndpoint(PROTOCOL, HOST, PORT, CONTEXT), new OpenShiftRuntimeInfo(runtimeConfig), new OpenShiftRuntimeState(STATE, STARTED_AT)); } }
public static OpenShiftProviderImpl createOpenShiftProvider() { return new OpenShiftProviderImpl(PROVIDER_ID, new OpenShiftProviderConfigImpl().clear()); } }
@Override public void start(RuntimeId runtimeId) throws RuntimeOperationException { OpenShiftRuntime runtime = (OpenShiftRuntime) runtimeRegistry.getRuntimeById(runtimeId.getId()); try { LOG.info("Starting runtime: " + runtimeId.getId()); openshift.getOpenShiftClient(runtime.getProviderId()).start(runtime.getId()); refresh(runtimeId); LOG.info("Started runtime: " + runtimeId.getId()); } catch (OpenShiftClientException ex) { LOG.error("Error Starting runtime: " + runtimeId.getId(), ex); throw new RuntimeOperationException("Error Starting runtime: " + runtimeId.getId(), ex); } }
@Override public boolean acceptProviderType(ProviderTypeKey providerTypeKey) { return providerTypeKey != null && OpenShiftProviderType.instance().getProviderTypeName().equals(providerTypeKey.getId()); }
@Override public Optional<OpenShiftProvider> apply(final OpenShiftProviderConfig openshiftProviderConfig) { if (openshiftProviderConfig.getName() == null || openshiftProviderConfig.getName().isEmpty()) { throw new ProvisioningException("No name was provided for the OpenShiftProviderConfig.getName() " + "configuration parameter. You might probably have to properly set " + "the pipeline input parameter: " + ProviderConfig.PROVIDER_NAME); } Provider provider = runtimeRegistry.getProvider(openshiftProviderConfig.getName()); OpenShiftProvider openshiftProvider; if (provider != null) { if (!(provider instanceof OpenShiftProvider)) { throw new ProvisioningException("The provider: " + openshiftProviderConfig.getName() + " must be an instance of " + OpenShiftProviderConfig.class + " but is: " + provider.getClass()); } else { openshiftProvider = (OpenShiftProvider) provider; } } else { openshiftProvider = new OpenShiftProviderImpl(openshiftProviderConfig.getName(), openshiftProviderConfig); runtimeRegistry.registerProvider(openshiftProvider); } return Optional.of(openshiftProvider); }
@Override public void pause(RuntimeId runtimeId) throws RuntimeOperationException { OpenShiftRuntime runtime = (OpenShiftRuntime) runtimeRegistry.getRuntimeById(runtimeId.getId()); try { LOG.info("Pausing runtime: " + runtimeId.getId()); openshift.getOpenShiftClient(runtime.getProviderId()).pause(runtime.getId()); refresh(runtimeId); LOG.info("Paused runtime: " + runtimeId.getId()); } catch (OpenShiftClientException ex) { LOG.error("Error Pausing runtime: " + runtimeId.getId(), ex); throw new RuntimeOperationException("Error Pausing runtime: " + runtimeId.getId(), ex); } }
@Override public boolean acceptProviderType(ProviderTypeKey providerTypeKey) { return providerTypeKey != null && OpenShiftProviderType.instance().getProviderTypeName().equals(providerTypeKey.getId()); }
@Override public void restart(RuntimeId runtimeId) throws RuntimeOperationException { OpenShiftRuntime runtime = (OpenShiftRuntime) runtimeRegistry.getRuntimeById(runtimeId.getId()); try { LOG.info("Restarting runtime: " + runtimeId.getId()); openshift.getOpenShiftClient(runtime.getProviderId()).restart(runtime.getId()); refresh(runtimeId); LOG.info("Restarted runtime: " + runtimeId.getId()); } catch (OpenShiftClientException ex) { LOG.error("Error Restarting runtime: " + runtimeId.getId(), ex); throw new RuntimeOperationException("Error Restarting runtime: " + runtimeId.getId(), ex); } }