@Override public void create() { try { StickinessPolicy result = _lbService.createLBStickinessPolicy(this); this.setEntityId(result.getId()); } catch (NetworkRuleConflictException e) { s_logger.warn("Exception: ", e); throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } }
@Override public Long getSyncObjId() { StickinessPolicy policy = _entityMgr.findById(StickinessPolicy.class, getId()); if (policy == null) { throw new InvalidParameterValueException("Unable to find LB stickiness rule: " + id); } LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId()); if (lb == null) { throw new InvalidParameterValueException( "Unable to find load balancer rule for stickiness rule: " + id); } return lb.getNetworkId(); }
public LBStickinessPolicyResponse(StickinessPolicy stickinesspolicy) { this.name = stickinesspolicy.getName(); List<Pair<String, String>> paramsList = stickinesspolicy.getParams(); this.methodName = stickinesspolicy.getMethodName(); this.description = stickinesspolicy.getDescription(); if (stickinesspolicy.isRevoke()) { this.setState("Revoked"); } if (stickinesspolicy.getId() != 0) setId(stickinesspolicy.getId()); /* Get the param and values from the database and fill the response object * The following loop is to * 1) convert from List of Pair<String,String> to Map<String, String> * 2) combine all params with name with ":" , currently we have one param called "domain" that can appear multiple times. * */ Map<String, String> tempParamList = new HashMap<String, String>(); for (Pair<String, String> paramKV : paramsList) { String key = paramKV.first(); String value = paramKV.second(); StringBuilder sb = new StringBuilder(); sb.append(value); if (tempParamList.get(key) != null) { sb.append(":").append(tempParamList.get(key)); } tempParamList.put(key, sb.toString()); } this.params = tempParamList; setObjectName("stickinesspolicy"); }
@Override public void execute() throws ResourceAllocationException, ResourceUnavailableException { StickinessPolicy policy = null; boolean success = false; try { UserContext.current().setEventDetails("Rule Id: " + getEntityId()); success = _lbService.applyLBStickinessPolicy(this); if (success) { // State might be different after the rule is applied, so get new object here policy = _entityMgr.findById(StickinessPolicy.class, getEntityId()); LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId()); LBStickinessResponse spResponse = _responseGenerator.createLBStickinessPolicyResponse(policy, lb); setResponseObject(spResponse); spResponse.setResponseName(getCommandName()); } } finally { if (!success || (policy == null)) { throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create stickiness policy "); } } }