Skip to content

Commit

Permalink
Merge pull request #246 from cliveseldon/versioning
Browse files Browse the repository at this point in the history
Add requestPath to response meta data
  • Loading branch information
ukclivecox authored Oct 3, 2018
2 parents 4d33644 + 06e781e commit d4594ca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,20 @@ public PredictiveUnitBean(){}

public SeldonMessage getOutput(SeldonMessage request, PredictiveUnitState state) throws InterruptedException, ExecutionException, InvalidProtocolBufferException{
Map<String,Integer> routingDict = new HashMap<String,Integer>();
SeldonMessage response = getOutputAsync(request, state, routingDict).get();
Map<String,String> requestPathDict = new HashMap<String,String>();
SeldonMessage response = getOutputAsync(request, state, routingDict,requestPathDict).get();
SeldonMessage.Builder builder = SeldonMessage
.newBuilder(response)
.setMeta(Meta
.newBuilder(response.getMeta()).putAllRouting(routingDict));
.newBuilder(response.getMeta()).putAllRouting(routingDict).putAllRequestPath(requestPathDict));
return builder.build();
}

@Async
private Future<SeldonMessage> getOutputAsync(SeldonMessage input, PredictiveUnitState state, Map<String,Integer> routingDict) throws InterruptedException, ExecutionException, InvalidProtocolBufferException{
private Future<SeldonMessage> getOutputAsync(SeldonMessage input, PredictiveUnitState state, Map<String,Integer> routingDict,Map<String,String> requestPathDict) throws InterruptedException, ExecutionException, InvalidProtocolBufferException{

// This element to the request path
requestPathDict.put(state.name, state.image);

// Getting the actual implementation (microservice or hardcoded? )
PredictiveUnitImpl implementation = predictorConfig.getImplementation(state);
Expand Down Expand Up @@ -105,7 +109,7 @@ private Future<SeldonMessage> getOutputAsync(SeldonMessage input, PredictiveUnit

// Get all the children outputs asynchronously
for (PredictiveUnitState childState : selectedChildren){
deferredChildrenOutputs.add(getOutputAsync(transformedInput,childState,routingDict));
deferredChildrenOutputs.add(getOutputAsync(transformedInput,childState,routingDict,requestPathDict));
}
for (Future<SeldonMessage> deferredOutput : deferredChildrenOutputs){
childrenOutputs.add(deferredOutput.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,26 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import io.kubernetes.client.proto.V1.Container;
import io.seldon.protos.DeploymentProtos.Endpoint;
import io.seldon.protos.DeploymentProtos.Parameter;
import io.seldon.protos.DeploymentProtos.PredictiveUnit;
import io.seldon.protos.DeploymentProtos.PredictiveUnit.PredictiveUnitImplementation;
import io.seldon.protos.DeploymentProtos.PredictiveUnit.PredictiveUnitMethod;
import io.seldon.protos.DeploymentProtos.PredictiveUnit.PredictiveUnitType;
import io.seldon.protos.DeploymentProtos.Parameter;

@JsonIgnoreProperties({"children","cluster_resources","id","subtype","type"})
public class PredictiveUnitState {
public String name;
public Endpoint endpoint;
public List<PredictiveUnitState> children = new ArrayList<>();
public Map<String,PredictiveUnitParameterInterface> parameters;
public String image = "";
public String imageName;
public String imageVersion;
public PredictiveUnitType type;
Expand Down Expand Up @@ -65,6 +67,12 @@ public PredictiveUnitState(
this.parameters = parameters;
this.imageName = imageName;
this.imageVersion = imageVersion;
if (!StringUtils.isEmpty(imageName) && !StringUtils.isEmpty(imageVersion))
this.image = imageName + ":" + imageVersion;
else if (!StringUtils.isEmpty(imageName))
this.image = imageName;
else
this.image = "";
this.type = type;
this.implementation = implementation;

Expand All @@ -78,7 +86,7 @@ public PredictiveUnitState(
this.parameters = deserializeParameters(predictiveUnit.getParametersList());

if (containersMap.containsKey(name)){
String image = containersMap.get(name).getImage();
this.image = containersMap.get(name).getImage();
if (image.contains(":"))
{
String[] parts = image.split(":");
Expand Down Expand Up @@ -114,6 +122,5 @@ public static Map<String,PredictiveUnitParameterInterface> deserializeParameters
public void addChild(PredictiveUnitState predictiveUnitState){
this.children.add(predictiveUnitState);
}

}

1 change: 1 addition & 0 deletions proto/prediction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ message Meta {
string puid = 1;
map<string,google.protobuf.Value> tags = 2;
map<string,int32> routing = 3;
map<string,string> requestPath = 4;
}

message SeldonMessageList {
Expand Down

0 comments on commit d4594ca

Please sign in to comment.