use of io.seldon.protos.DeploymentProtos.SeldonDeployment in project seldon-core by SeldonIO.
the class SeldonDeploymentControllerImpl method createOrReplaceSeldonDeployment.
@Override
public void createOrReplaceSeldonDeployment(SeldonDeployment mlDep) {
if (mlDep.hasStatus() && mlDep.getStatus().hasState() && mlDep.getStatus().getState().equals(FAILED_STATE_MSG)) {
logger.warn("Ignoring failed deployment " + mlDep.getMetadata().getName());
return;
}
try {
SeldonDeployment existing = mlCache.get(mlDep.getMetadata().getName());
if (existing == null || !existing.getSpec().equals(mlDep.getSpec())) {
logger.debug("Running updates for " + mlDep.getMetadata().getName());
SeldonDeployment mlDep2 = operator.defaulting(mlDep);
operator.validate(mlDep2);
mlCache.put(mlDep2);
DeploymentResources resources = operator.createResources(mlDep2);
ProtoClient client = clientProvider.getProtoClient();
String namespace = getNamespace(mlDep2);
createDeployments(client, namespace, resources.deployments);
removeDeployments(client, namespace, mlDep2, resources.deployments);
createService(client, namespace, resources.service);
if (!mlDep.getSpec().equals(mlDep2.getSpec())) {
logger.debug("Pushing updated SeldonDeployment " + mlDep2.getMetadata().getName() + " back to kubectl");
crdHandler.updateSeldonDeployment(mlDep2);
} else
logger.debug("Not pushing an update as no change to spec for SeldonDeployment " + mlDep2.getMetadata().getName());
} else {
mlCache.put(mlDep);
logger.debug("Only updated cache for " + mlDep.getMetadata().getName());
}
} catch (SeldonDeploymentException e) {
logger.error("Failed to create deployment ", e);
failDeployment(mlDep, e);
} catch (ApiException e) {
logger.error("Kubernetes API exception deploying code:" + e.getCode() + "message:" + e.getResponseBody(), e);
failDeployment(mlDep, e);
} catch (IOException e) {
logger.error("IOException during createReplace ", e);
failDeployment(mlDep, e);
}
}
use of io.seldon.protos.DeploymentProtos.SeldonDeployment in project seldon-core by SeldonIO.
the class SeldonDeploymentControllerImpl method removeDeployments.
private void removeDeployments(ProtoClient client, String namespace, SeldonDeployment seldonDeployment, List<Deployment> deployments) throws ApiException, IOException, SeldonDeploymentException {
Set<String> names = getDeploymentNames(deployments);
ExtensionsV1beta1DeploymentList depList = crdHandler.getOwnedDeployments(seldonDeployment.getSpec().getName());
for (ExtensionsV1beta1Deployment d : depList.getItems()) {
if (!names.contains(d.getMetadata().getName())) {
final String deleteApiPath = "/apis/" + DEPLOYMENT_API_VERSION + "/namespaces/{namespace}/deployments/{name}".replaceAll("\\{" + "name" + "\\}", client.getApiClient().escapeString(d.getMetadata().getName())).replaceAll("\\{" + "namespace" + "\\}", client.getApiClient().escapeString(namespace));
DeleteOptions options = DeleteOptions.newBuilder().setPropagationPolicy("Foreground").build();
ObjectOrStatus<Deployment> os = client.delete(Deployment.newBuilder(), deleteApiPath, options);
if (os.status != null) {
logger.error("Error deleting deployment:" + ProtoBufUtils.toJson(os.status));
throw new SeldonDeploymentException("Failed to delete deployment " + d.getMetadata().getName());
} else {
logger.debug("Deleted deployment:" + ProtoBufUtils.toJson(os.object));
}
}
}
}
use of io.seldon.protos.DeploymentProtos.SeldonDeployment in project seldon-core by SeldonIO.
the class SeldonDeploymentOperatorImpl method defaulting.
@Override
public SeldonDeployment defaulting(SeldonDeployment mlDep) {
SeldonDeployment.Builder mlBuilder = SeldonDeployment.newBuilder(mlDep);
int idx = 0;
String serviceName = mlDep.getSpec().getName();
String deploymentName = mlDep.getMetadata().getName();
for (PredictorSpec p : mlDep.getSpec().getPredictorsList()) {
ObjectMeta.Builder metaBuilder = ObjectMeta.newBuilder(p.getComponentSpec().getMetadata()).putLabels(LABEL_SELDON_APP, serviceName);
mlBuilder.getSpecBuilder().getPredictorsBuilder(idx).getComponentSpecBuilder().setMetadata(metaBuilder);
int cIdx = 0;
mlBuilder.getSpecBuilder().getPredictorsBuilder(idx).getComponentSpecBuilder().getSpecBuilder().clearContainers();
String predictorName = p.getName();
for (V1.Container c : p.getComponentSpec().getSpec().getContainersList()) {
V1.Container c2 = this.updateContainer(c, findPredictiveUnitForContainer(mlDep.getSpec().getPredictors(idx).getGraph(), c.getName()), cIdx, deploymentName, predictorName);
mlBuilder.getSpecBuilder().getPredictorsBuilder(idx).getComponentSpecBuilder().getSpecBuilder().addContainers(cIdx, c2);
updatePredictiveUnitBuilderByName(mlBuilder.getSpecBuilder().getPredictorsBuilder(idx).getGraphBuilder(), c2);
cIdx++;
}
idx++;
}
return mlBuilder.build();
}
use of io.seldon.protos.DeploymentProtos.SeldonDeployment in project seldon-core by SeldonIO.
the class SeldonDeploymentStatusUpdateImpl method removeStatus.
@Override
public void removeStatus(String mlDepName, String depName) {
logger.info(String.format("DELETE %s : %s", mlDepName, depName));
SeldonDeployment mlDep = crdHandler.getSeldonDeployment(mlDepName);
if (mlDep != null) {
SeldonDeployment.Builder mlBuilder = SeldonDeployment.newBuilder(mlDep);
int idx = 0;
for (PredictorStatus.Builder b : mlBuilder.getStatusBuilder().getPredictorStatusBuilderList()) {
if (b.getName().equals(depName)) {
mlBuilder.getStatusBuilder().removePredictorStatus(idx);
break;
}
}
crdHandler.updateSeldonDeployment(mlBuilder.build());
} else
logger.error("Can't find seldondeployment " + mlDepName + " to remove " + depName);
}
use of io.seldon.protos.DeploymentProtos.SeldonDeployment in project seldon-core by SeldonIO.
the class AuthorizationServerConfiguration method configure.
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.withClientDetails(clientDetailsService);
String client_key = System.getenv().get(TEST_CLIENT_KEY);
// Create Fake seldon deployment for testing
if (client_key != null) {
String client_secret = System.getenv().get(TEST_CLIENT_SECRET);
clientDetailsService.addClient(client_key, client_secret);
SeldonDeployment dep = SeldonDeployment.newBuilder().setApiVersion("v1alpha1").setKind("SeldonDeplyment").setSpec(DeploymentSpec.newBuilder().setName("localhost").setOauthKey(client_key).setOauthSecret(client_secret)).build();
deploymentStore.deploymentAdded(dep);
}
}
Aggregations