Search in sources :

Example 6 with SeldonDeployment

use of io.seldon.protos.DeploymentProtos.SeldonDeployment in project seldon-core by SeldonIO.

the class SeldonGrpcServer method main.

/**
 * Main method for basic testing.
 */
public static void main(String[] args) throws Exception {
    DeploymentStore store = new DeploymentStore(null, new InMemoryClientDetailsService());
    SeldonDeployment dep = SeldonDeployment.newBuilder().setApiVersion("v1alpha1").setKind("SeldonDeplyment").setSpec(DeploymentSpec.newBuilder().setName("0.0.0.0").setOauthKey("key").setOauthSecret("secret")).build();
    AppProperties appProperties = new AppProperties();
    appProperties.setEngineGrpcContainerPort(5000);
    store.deploymentAdded(dep);
    SeldonGrpcServer server = new SeldonGrpcServer(appProperties, store, null, null, SERVER_PORT);
    server.start();
    server.blockUntilShutdown();
}
Also used : InMemoryClientDetailsService(io.seldon.apife.api.oauth.InMemoryClientDetailsService) DeploymentStore(io.seldon.apife.deployments.DeploymentStore) SeldonDeployment(io.seldon.protos.DeploymentProtos.SeldonDeployment) AppProperties(io.seldon.apife.AppProperties)

Example 7 with SeldonDeployment

use of io.seldon.protos.DeploymentProtos.SeldonDeployment in project seldon-core by SeldonIO.

the class KubeCRDHandlerImpl method updateSeldonDeployment.

@Override
public void updateSeldonDeployment(SeldonDeployment mldep) {
    try {
        // Need to remove resourceVersion from the representation used for last-applied-configuration otherwise you will errors subsequently using kubectl
        SeldonDeployment mlDepTmp = SeldonDeployment.newBuilder(mldep).setMetadata(ObjectMeta.newBuilder(mldep.getMetadata()).clearResourceVersion().removeAnnotations("kubectl.kubernetes.io/last-applied-configuration").build()).build();
        // Create string representation of JSON to add as annotation to allow declarative "kubectl apply" commands to work otherwise a replace
        // would remove the last-applied-configuration that kubectl adds.
        String json = SeldonDeploymentUtils.toJson(mlDepTmp, true);
        // Create final version of deployment with annotation
        SeldonDeployment mlDeployment = SeldonDeployment.newBuilder(mldep).setMetadata(ObjectMeta.newBuilder(mldep.getMetadata()).putAnnotations("kubectl.kubernetes.io/last-applied-configuration", json + "\n")).build();
        json = SeldonDeploymentUtils.toJson(mlDeployment, false);
        logger.debug("Updating seldondeployment " + mlDeployment.getMetadata().getName());
        ApiClient client = Config.defaultClient();
        CustomObjectsApi api = new CustomObjectsApi(client);
        api.replaceNamespacedCustomObject(GROUP, VERSION, namespace, KIND_PLURAL, mlDeployment.getMetadata().getName(), json.getBytes());
    } catch (InvalidProtocolBufferException e) {
        logger.error("Failed to update deployment in kubernetes ", e);
    } catch (ApiException e) {
        logger.error("Failed to update deployment in kubernetes ", e);
    } catch (IOException e) {
        logger.error("Failed to get client ", e);
    } finally {
    }
}
Also used : CustomObjectsApi(io.kubernetes.client.apis.CustomObjectsApi) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) IOException(java.io.IOException) ApiClient(io.kubernetes.client.ApiClient) SeldonDeployment(io.seldon.protos.DeploymentProtos.SeldonDeployment) ApiException(io.kubernetes.client.ApiException)

Example 8 with SeldonDeployment

use of io.seldon.protos.DeploymentProtos.SeldonDeployment in project seldon-core by SeldonIO.

the class EnginePredictor method init.

public void init() throws Exception {
    logger.info("init");
    {
        // setup the PredictorSpec using the env vars
        String enginePredictorBase64Encoded = System.getenv().get(ENGINE_PREDICTOR_KEY);
        if (enginePredictorBase64Encoded == null) {
            String filePath = "./deploymentdef.json";
            File deploymentFile = new File(filePath);
            if (deploymentFile.exists()) {
                logger.error("FAILED to find env var [{}], will use json file", ENGINE_PREDICTOR_KEY);
                byte[] encoded = Files.readAllBytes(Paths.get(filePath));
                String enginePredictorJson = new String(encoded);
                PredictorSpec.Builder PredictorSpecBuilder = PredictorSpec.newBuilder();
                try {
                    updateMessageBuilderFromJson(PredictorSpecBuilder, enginePredictorJson);
                } catch (Exception e) {
                    logger.error("FAILED building PredictorSpec from file content", ENGINE_PREDICTOR_KEY, e);
                    throw e;
                }
                predictorSpec = PredictorSpecBuilder.build();
            } else {
                logger.error("FAILED to find env var [{}], will use defaults for engine predictor", ENGINE_PREDICTOR_KEY);
                predictorSpec = buildDefaultPredictorSpec();
            }
        } else {
            logger.info("FOUND env var [{}], will use for engine predictor", ENGINE_PREDICTOR_KEY);
            byte[] enginePredictorBytes = Base64.getDecoder().decode(enginePredictorBase64Encoded);
            String enginePredictorJson = new String(enginePredictorBytes);
            PredictorSpec.Builder PredictorSpecBuilder = PredictorSpec.newBuilder();
            try {
                updateMessageBuilderFromJson(PredictorSpecBuilder, enginePredictorJson);
            } catch (Exception e) {
                logger.error("FAILED extracting PredictorSpec from env var [{}]", ENGINE_PREDICTOR_KEY, e);
                throw e;
            }
            predictorSpec = PredictorSpecBuilder.build();
        }
        // Get overall deployment
        {
            String engineDeploymentBase64Encoded = System.getenv().get(ENGINE_SELDON_DEPLOYMENT_KEY);
            if (engineDeploymentBase64Encoded != null) {
                byte[] engineDeploymentBytes = Base64.getDecoder().decode(engineDeploymentBase64Encoded);
                String engineDeploymentJson = new String(engineDeploymentBytes);
                SeldonDeployment.Builder depBuilder = SeldonDeployment.newBuilder();
                try {
                    updateMessageBuilderFromJson(depBuilder, engineDeploymentJson);
                } catch (Exception e) {
                    logger.error("FAILED extracting SeldonDeployment from env var [{}]", ENGINE_SELDON_DEPLOYMENT_KEY, e);
                    throw e;
                }
                seldonDeployment = depBuilder.build();
            } else
                logger.warn("Failed to find SeldonDeployment in [{}]", ENGINE_SELDON_DEPLOYMENT_KEY);
        }
    }
    logger.info("Installed engine predictor: {}", toJson(predictorSpec, true));
}
Also used : IntOrString(io.kubernetes.client.proto.IntStr.IntOrString) File(java.io.File) SeldonDeployment(io.seldon.protos.DeploymentProtos.SeldonDeployment) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException)

Example 9 with SeldonDeployment

use of io.seldon.protos.DeploymentProtos.SeldonDeployment in project seldon-core by SeldonIO.

the class SeldonDeploymentDefaultingTest method testDefaultingGrpc.

@Test
public void testDefaultingGrpc() throws IOException {
    SeldonDeploymentOperator op = new SeldonDeploymentOperatorImpl(getClusterManagerprops());
    String jsonStr = readFile("src/test/resources/model_simple_grpc.json", StandardCharsets.UTF_8);
    SeldonDeployment mlDep = SeldonDeploymentUtils.jsonToSeldonDeployment(jsonStr);
    SeldonDeployment mlDep2 = op.defaulting(mlDep);
    Assert.assertTrue(mlDep2.getSpec().getPredictors(0).getComponentSpec().getSpec().getContainers(0).hasLivenessProbe());
    Assert.assertTrue(mlDep2.getSpec().getPredictors(0).getComponentSpec().getSpec().getContainers(0).hasReadinessProbe());
    Assert.assertTrue(mlDep2.getSpec().getPredictors(0).getComponentSpec().getSpec().getContainers(0).hasLifecycle());
    Assert.assertEquals("Incorrect number of environment variables in container", 5, mlDep2.getSpec().getPredictors(0).getComponentSpec().getSpec().getContainers(0).getEnvCount());
    Assert.assertEquals(1, mlDep2.getSpec().getPredictors(0).getComponentSpec().getSpec().getContainers(0).getPortsCount());
    Assert.assertEquals("grpc", mlDep2.getSpec().getPredictors(0).getComponentSpec().getSpec().getContainers(0).getPorts(0).getName());
    Assert.assertEquals(Endpoint.EndpointType.GRPC_VALUE, mlDep2.getSpec().getPredictors(0).getGraph().getEndpoint().getType().getNumber());
    Assert.assertEquals("0.0.0.0", mlDep2.getSpec().getPredictors(0).getGraph().getEndpoint().getServiceHost());
}
Also used : SeldonDeployment(io.seldon.protos.DeploymentProtos.SeldonDeployment) AppTest(io.seldon.clustermanager.AppTest) Test(org.junit.Test)

Example 10 with SeldonDeployment

use of io.seldon.protos.DeploymentProtos.SeldonDeployment in project seldon-core by SeldonIO.

the class SeldonDeploymentDefaultingTest method testDefaulting.

@Test
public void testDefaulting() throws IOException {
    SeldonDeploymentOperator op = new SeldonDeploymentOperatorImpl(getClusterManagerprops());
    String jsonStr = readFile("src/test/resources/model_simple.json", StandardCharsets.UTF_8);
    SeldonDeployment mlDep = SeldonDeploymentUtils.jsonToSeldonDeployment(jsonStr);
    SeldonDeployment mlDep2 = op.defaulting(mlDep);
    Assert.assertTrue(mlDep2.getSpec().getPredictors(0).getComponentSpec().getSpec().getContainers(0).hasLivenessProbe());
    Assert.assertTrue(mlDep2.getSpec().getPredictors(0).getComponentSpec().getSpec().getContainers(0).hasReadinessProbe());
    Assert.assertTrue(mlDep2.getSpec().getPredictors(0).getComponentSpec().getSpec().getContainers(0).hasLifecycle());
    Assert.assertEquals("Incorrect number of environment variables in container", 5, mlDep2.getSpec().getPredictors(0).getComponentSpec().getSpec().getContainers(0).getEnvCount());
    Assert.assertEquals(1, mlDep2.getSpec().getPredictors(0).getComponentSpec().getSpec().getContainers(0).getPortsCount());
    Assert.assertEquals("http", mlDep2.getSpec().getPredictors(0).getComponentSpec().getSpec().getContainers(0).getPorts(0).getName());
    Assert.assertEquals(Endpoint.EndpointType.REST_VALUE, mlDep2.getSpec().getPredictors(0).getGraph().getEndpoint().getType().getNumber());
    Assert.assertEquals("0.0.0.0", mlDep2.getSpec().getPredictors(0).getGraph().getEndpoint().getServiceHost());
}
Also used : SeldonDeployment(io.seldon.protos.DeploymentProtos.SeldonDeployment) AppTest(io.seldon.clustermanager.AppTest) Test(org.junit.Test)

Aggregations

SeldonDeployment (io.seldon.protos.DeploymentProtos.SeldonDeployment)15 AppTest (io.seldon.clustermanager.AppTest)5 Test (org.junit.Test)5 IntOrString (io.kubernetes.client.proto.IntStr.IntOrString)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 ApiException (io.kubernetes.client.ApiException)2 Deployment (io.kubernetes.client.proto.V1beta1Extensions.Deployment)2 PredictorSpec (io.seldon.protos.DeploymentProtos.PredictorSpec)2 PredictorStatus (io.seldon.protos.DeploymentProtos.PredictorStatus)2 IOException (java.io.IOException)2 ApiClient (io.kubernetes.client.ApiClient)1 ProtoClient (io.kubernetes.client.ProtoClient)1 CustomObjectsApi (io.kubernetes.client.apis.CustomObjectsApi)1 ExtensionsV1beta1Deployment (io.kubernetes.client.models.ExtensionsV1beta1Deployment)1 ExtensionsV1beta1DeploymentList (io.kubernetes.client.models.ExtensionsV1beta1DeploymentList)1 V1OwnerReference (io.kubernetes.client.models.V1OwnerReference)1 DeleteOptions (io.kubernetes.client.proto.Meta.DeleteOptions)1 ObjectMeta (io.kubernetes.client.proto.Meta.ObjectMeta)1 OwnerReference (io.kubernetes.client.proto.Meta.OwnerReference)1 V1 (io.kubernetes.client.proto.V1)1