Search in sources :

Example 1 with OpenShiftRuntimeEndpoint

use of org.guvnor.ala.openshift.model.OpenShiftRuntimeEndpoint in project kie-wb-common by kiegroup.

the class OpenShiftRuntimeExecExecutor method create.

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));
}
Also used : OpenShiftRuntime(org.guvnor.ala.openshift.model.OpenShiftRuntime) OpenShiftClient(org.guvnor.ala.openshift.access.OpenShiftClient) ProvisioningException(org.guvnor.ala.exceptions.ProvisioningException) OpenShiftProvider(org.guvnor.ala.openshift.model.OpenShiftProvider) OpenShiftRuntimeState(org.guvnor.ala.openshift.model.OpenShiftRuntimeState) OpenShiftClientException(org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException) OpenShiftRuntimeInfo(org.guvnor.ala.openshift.model.OpenShiftRuntimeInfo) OpenShiftRuntimeEndpoint(org.guvnor.ala.openshift.model.OpenShiftRuntimeEndpoint)

Example 2 with OpenShiftRuntimeEndpoint

use of org.guvnor.ala.openshift.model.OpenShiftRuntimeEndpoint in project kie-wb-common by kiegroup.

the class OpenShiftClient method getRuntimeEndpoint.

public OpenShiftRuntimeEndpoint getRuntimeEndpoint(String id) throws OpenShiftClientException {
    try {
        OpenShiftRuntimeId runtimeId = OpenShiftRuntimeId.fromString(id);
        String prjName = runtimeId.project();
        String svcName = runtimeId.service();
        OpenShiftRuntimeEndpoint endpoint = new OpenShiftRuntimeEndpoint();
        Route route = delegate.routes().inNamespace(prjName).withName(svcName).get();
        if (route != null) {
            RouteSpec routeSpec = route.getSpec();
            endpoint.setProtocol(routeSpec.getTls() != null ? "https" : "http");
            endpoint.setHost(routeSpec.getHost());
            RoutePort routePort = routeSpec.getPort();
            if (routePort != null) {
                IntOrString targetPort = routePort.getTargetPort();
                if (targetPort != null) {
                    endpoint.setPort(targetPort.getIntVal());
                }
            }
        }
        return endpoint;
    } catch (Throwable t) {
        throw new OpenShiftClientException(t.getMessage(), t);
    }
}
Also used : RoutePort(io.fabric8.openshift.api.model.RoutePort) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) OpenShiftClientException(org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) RouteSpec(io.fabric8.openshift.api.model.RouteSpec) OpenShiftRuntimeEndpoint(org.guvnor.ala.openshift.model.OpenShiftRuntimeEndpoint) Route(io.fabric8.openshift.api.model.Route)

Example 3 with OpenShiftRuntimeEndpoint

use of org.guvnor.ala.openshift.model.OpenShiftRuntimeEndpoint in project kie-wb-common by kiegroup.

the class OpenShiftExecutorTest method testPipelineAndLifecycle.

/**
 * Tests the ALA pipeline and runtime lifecycle.
 *
 * If running via command line, the properties are already set in the pom.xml file.
 * If running in an IDE, set these properties in your debug configuration VM arguments.
 * On Eclipse, Run / Debug Configurations... / Arguments / VM arguments:
 * -Dsun.net.spi.nameservice.provider.1=dns,OpenShiftNameService
 * -Dsun.net.spi.nameservice.provider.2=default
 * -Dorg.guvnor.ala.openshift.access.OpenShiftClientListener.postCreate=org.guvnor.ala.openshift.dns.OpenShiftNameServiceClientListener
 * -Dorg.guvnor.ala.openshift.dns.OpenShiftNameServiceClientListener.routerHost=10.34.75.115
 *
 * @throws Exception
 */
@Test
public void testPipelineAndLifecycle() throws Exception {
    final RuntimeRegistry runtimeRegistry = new InMemoryRuntimeRegistry();
    final OpenShiftAccessInterface openshiftAccessInterface = new OpenShiftAccessInterfaceImpl();
    final Pipeline pipe = PipelineFactory.newBuilder().addConfigStage("OpenShift Provider Config", new OpenShiftProviderConfig() {
    }).addConfigStage("OpenShift Runtime Config", new ContextAwareOpenShiftRuntimeExecConfig()).buildAs("my pipe");
    final OpenShiftRuntimeExecExecutor<OpenShiftRuntimeExecConfig> openshiftRuntimeExecExecutor = new OpenShiftRuntimeExecExecutor<>(runtimeRegistry, openshiftAccessInterface);
    final PipelineExecutor executor = new PipelineExecutor(asList(new OpenShiftProviderConfigExecutor(runtimeRegistry), openshiftRuntimeExecExecutor));
    final String pvrName = getClass().getSimpleName();
    final String prjName = createProjectName("tpal1");
    final String appName = "myapp";
    final String svcName = appName + "-execserv";
    final String kieServerUser = "executionUser";
    final String kieServerPwd = "execution1!";
    String templateParams = new OpenShiftParameters().param("APPLICATION_NAME", appName).param("IMAGE_STREAM_NAMESPACE", prjName).param("KIE_ADMIN_PWD", "admin1!").param("KIE_SERVER_USER", kieServerUser).param("KIE_SERVER_PWD", kieServerPwd).param("MAVEN_REPO_URL", "http://repository.jboss.org/nexus/content/groups/public/").toString();
    Input input = new Input() {

        {
            /*
            // build properties
            put(GitConfig.ORIGIN, "https://github.com/jboss-openshift/openshift-quickstarts");
            put(GitConfig.REPO_NAME, "openshift-quickstarts");
            put(GitConfig.BRANCH,  "main");
            put(GitConfig.CREATE_REPO,  "true");
            put(GitConfig.OUT_DIR,  workDir.getAbsolutePath());
            put(MavenProjectConfig.PROJECT_DIR, "decisionserver/hellorules");
            */
            // provider properties
            put(KUBERNETES_MAIN.inputKey(), "https://ce-os-rhel-main.usersys.redhat.com:8443");
            put(KUBERNETES_AUTH_BASIC_USERNAME.inputKey(), "admin");
            put(KUBERNETES_AUTH_BASIC_PASSWORD.inputKey(), "admin");
            put(PROVIDER_NAME.inputKey(), pvrName);
            // runtime properties
            put(APPLICATION_NAME.inputKey(), appName);
            // put(KIE_SERVER_CONTAINER_DEPLOYMENT.inputKey(), "decisionserver-hellorules=org.openshift.quickstarts:decisionserver-hellorules:1.4.0.Final");
            put(PROJECT_NAME.inputKey(), prjName);
            put(RESOURCE_SECRETS_URI.inputKey(), getUri("bpmsuite-app-secret.json"));
            put(RESOURCE_STREAMS_URI.inputKey(), getUri("bpmsuite-image-streams.json"));
            put(RESOURCE_TEMPLATE_PARAM_VALUES.inputKey(), templateParams);
            put(RESOURCE_TEMPLATE_URI.inputKey(), getUri("bpmsuite70-execserv.json"));
            put(SERVICE_NAME.inputKey(), svcName);
        }
    };
    executor.execute(input, pipe, (Runtime b) -> System.out.println(b));
    OpenShiftRuntimeManager runtimeManager = new OpenShiftRuntimeManager(runtimeRegistry, openshiftAccessInterface);
    OpenShiftRuntime openshiftRuntime = getRuntime(runtimeRegistry, runtimeManager, null, true);
    assertEquals(OpenShiftRuntimeState.READY, openshiftRuntime.getState().getState());
    // This step would normally be done by guvnor, but since we don't have guvnor in this test, we
    // include a standalone Nexus repo in the json configuration and deploy the binary to it here.
    // new OpenShiftMavenDeployer(workDir, appName, prjName).deploy(buildRegistry);
    runtimeManager.start(openshiftRuntime);
    openshiftRuntime = getRuntime(runtimeRegistry, runtimeManager, openshiftRuntime, true);
    assertEquals(OpenShiftRuntimeState.RUNNING, openshiftRuntime.getState().getState());
    RuntimeEndpoint runtimeEndpoint = openshiftRuntime.getEndpoint();
    assertTrue(runtimeEndpoint instanceof OpenShiftRuntimeEndpoint);
    OpenShiftRuntimeEndpoint openshiftRuntimeEndpoint = (OpenShiftRuntimeEndpoint) runtimeEndpoint;
    String kieServerHost = openshiftRuntimeEndpoint.getHost();
    if (OpenShiftNameService.isHostRegistered(kieServerHost)) {
        String kieServerUrl = new StringBuilder().append(openshiftRuntimeEndpoint.getProtocol()).append("://").append(kieServerHost).append("/services/rest/server").toString();
        if (checkConnection(kieServerUrl)) {
            KieServicesConfiguration kieServicesConfig = KieServicesFactory.newRestConfiguration(kieServerUrl, kieServerUser, kieServerPwd);
            KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(kieServicesConfig);
            ServiceResponse<KieServerInfo> serverInfoResponse = kieServicesClient.getServerInfo();
            assertEquals(ServiceResponse.ResponseType.SUCCESS, serverInfoResponse.getType());
        }
    }
    runtimeManager.stop(openshiftRuntime);
    openshiftRuntime = getRuntime(runtimeRegistry, runtimeManager, openshiftRuntime, true);
    assertEquals(OpenShiftRuntimeState.READY, openshiftRuntime.getState().getState());
    openshiftRuntimeExecExecutor.destroy(openshiftRuntime);
    openshiftRuntime = getRuntime(runtimeRegistry, runtimeManager, openshiftRuntime, false);
    assertNull(openshiftRuntime);
    openshiftAccessInterface.dispose();
}
Also used : OpenShiftRuntimeExecConfig(org.guvnor.ala.openshift.config.OpenShiftRuntimeExecConfig) ContextAwareOpenShiftRuntimeExecConfig(org.guvnor.ala.openshift.config.impl.ContextAwareOpenShiftRuntimeExecConfig) OpenShiftAccessInterface(org.guvnor.ala.openshift.access.OpenShiftAccessInterface) RuntimeEndpoint(org.guvnor.ala.runtime.RuntimeEndpoint) OpenShiftRuntimeEndpoint(org.guvnor.ala.openshift.model.OpenShiftRuntimeEndpoint) KieServicesClient(org.kie.server.client.KieServicesClient) OpenShiftProviderConfig(org.guvnor.ala.openshift.config.OpenShiftProviderConfig) PipelineExecutor(org.guvnor.ala.pipeline.execution.PipelineExecutor) Input(org.guvnor.ala.pipeline.Input) OpenShiftRuntime(org.guvnor.ala.openshift.model.OpenShiftRuntime) Runtime(org.guvnor.ala.runtime.Runtime) OpenShiftParameters(org.guvnor.ala.openshift.config.OpenShiftParameters) OpenShiftAccessInterfaceImpl(org.guvnor.ala.openshift.access.impl.OpenShiftAccessInterfaceImpl) OpenShiftRuntimeManager(org.guvnor.ala.openshift.service.OpenShiftRuntimeManager) OpenShiftRuntime(org.guvnor.ala.openshift.model.OpenShiftRuntime) KieServicesConfiguration(org.kie.server.client.KieServicesConfiguration) KieServerInfo(org.kie.server.api.model.KieServerInfo) RuntimeRegistry(org.guvnor.ala.registry.RuntimeRegistry) InMemoryRuntimeRegistry(org.guvnor.ala.registry.inmemory.InMemoryRuntimeRegistry) OpenShiftRuntimeEndpoint(org.guvnor.ala.openshift.model.OpenShiftRuntimeEndpoint) Pipeline(org.guvnor.ala.pipeline.Pipeline) ContextAwareOpenShiftRuntimeExecConfig(org.guvnor.ala.openshift.config.impl.ContextAwareOpenShiftRuntimeExecConfig) InMemoryRuntimeRegistry(org.guvnor.ala.registry.inmemory.InMemoryRuntimeRegistry) Test(org.junit.Test)

Example 4 with OpenShiftRuntimeEndpoint

use of org.guvnor.ala.openshift.model.OpenShiftRuntimeEndpoint in project kie-wb-common by kiegroup.

the class OpenShiftRuntimeMarshallerTest method getValue.

@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));
}
Also used : ContextAwareOpenShiftRuntimeExecConfig(org.guvnor.ala.openshift.config.impl.ContextAwareOpenShiftRuntimeExecConfig) OpenShiftRuntime(org.guvnor.ala.openshift.model.OpenShiftRuntime) OpenShiftProviderImplMarshallerTest.createOpenShiftProvider(org.guvnor.ala.openshift.marshalling.OpenShiftProviderImplMarshallerTest.createOpenShiftProvider) OpenShiftProvider(org.guvnor.ala.openshift.model.OpenShiftProvider) OpenShiftRuntimeState(org.guvnor.ala.openshift.model.OpenShiftRuntimeState) OpenShiftRuntimeInfo(org.guvnor.ala.openshift.model.OpenShiftRuntimeInfo) OpenShiftRuntimeEndpoint(org.guvnor.ala.openshift.model.OpenShiftRuntimeEndpoint) OpenShiftRuntimeConfig(org.guvnor.ala.openshift.config.OpenShiftRuntimeConfig)

Aggregations

OpenShiftRuntimeEndpoint (org.guvnor.ala.openshift.model.OpenShiftRuntimeEndpoint)4 OpenShiftRuntime (org.guvnor.ala.openshift.model.OpenShiftRuntime)3 OpenShiftClientException (org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException)2 ContextAwareOpenShiftRuntimeExecConfig (org.guvnor.ala.openshift.config.impl.ContextAwareOpenShiftRuntimeExecConfig)2 OpenShiftProvider (org.guvnor.ala.openshift.model.OpenShiftProvider)2 OpenShiftRuntimeInfo (org.guvnor.ala.openshift.model.OpenShiftRuntimeInfo)2 OpenShiftRuntimeState (org.guvnor.ala.openshift.model.OpenShiftRuntimeState)2 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)1 Route (io.fabric8.openshift.api.model.Route)1 RoutePort (io.fabric8.openshift.api.model.RoutePort)1 RouteSpec (io.fabric8.openshift.api.model.RouteSpec)1 ProvisioningException (org.guvnor.ala.exceptions.ProvisioningException)1 OpenShiftAccessInterface (org.guvnor.ala.openshift.access.OpenShiftAccessInterface)1 OpenShiftClient (org.guvnor.ala.openshift.access.OpenShiftClient)1 OpenShiftAccessInterfaceImpl (org.guvnor.ala.openshift.access.impl.OpenShiftAccessInterfaceImpl)1 OpenShiftParameters (org.guvnor.ala.openshift.config.OpenShiftParameters)1 OpenShiftProviderConfig (org.guvnor.ala.openshift.config.OpenShiftProviderConfig)1 OpenShiftRuntimeConfig (org.guvnor.ala.openshift.config.OpenShiftRuntimeConfig)1 OpenShiftRuntimeExecConfig (org.guvnor.ala.openshift.config.OpenShiftRuntimeExecConfig)1 OpenShiftProviderImplMarshallerTest.createOpenShiftProvider (org.guvnor.ala.openshift.marshalling.OpenShiftProviderImplMarshallerTest.createOpenShiftProvider)1