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();
}
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 {
}
}
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));
}
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());
}
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());
}
Aggregations