package com.cloud.api.commands; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.log4j.Logger; import com.cloud.api.BaseCmd; import com.cloud.api.ServerApiException; import com.cloud.network.LoadBalancerVO; import com.cloud.user.Account; import com.cloud.utils.Pair; public class UpdateLoadBalancerRuleCmd extends BaseCmd { public static final Logger s_logger = Logger.getLogger(UpdateLoadBalancerRuleCmd.class.getName()); private static final String s_name = "updateloadbalancerruleresponse"; private static final List> s_properties = new ArrayList>(); static { s_properties.add(new Pair(BaseCmd.Properties.USER_ID, Boolean.FALSE)); s_properties.add(new Pair(BaseCmd.Properties.ACCOUNT_OBJ, Boolean.FALSE)); s_properties.add(new Pair(BaseCmd.Properties.NAME, Boolean.FALSE)); s_properties.add(new Pair(BaseCmd.Properties.DESCRIPTION, Boolean.FALSE)); s_properties.add(new Pair(BaseCmd.Properties.PRIVATE_PORT, Boolean.FALSE)); s_properties.add(new Pair(BaseCmd.Properties.ALGORITHM, Boolean.FALSE)); s_properties.add(new Pair(BaseCmd.Properties.ID, Boolean.TRUE)); } public String getName() { return s_name; } public List> getProperties() { return s_properties; } @Override public List> execute(Map params) { Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName()); Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName()); String name = (String)params.get(BaseCmd.Properties.NAME.getName()); String description = (String)params.get(BaseCmd.Properties.DESCRIPTION.getName()); String privatePort = (String)params.get(BaseCmd.Properties.PRIVATE_PORT.getName()); String algorithm = (String)params.get(BaseCmd.Properties.ALGORITHM.getName()); Long loadBalancerId = (Long)params.get(BaseCmd.Properties.ID.getName()); if (userId == null) { userId = Long.valueOf(1); } LoadBalancerVO lb = getManagementServer().findLoadBalancerById(loadBalancerId); if (lb == null) { throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to find load balancer rule " + loadBalancerId + " for update."); } // Verify input parameters Account lbOwner = getManagementServer().findAccountById(lb.getAccountId()); if (lbOwner == null) { throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to update load balancer rule, cannot find owning account"); } Long accountId = lbOwner.getId(); if (account != null) { if (!isAdmin(account.getType())) { if (account.getId().longValue() != accountId.longValue()) { throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to update load balancer rule, permission denied"); } } else if (!getManagementServer().isChildDomain(account.getDomainId(), lbOwner.getDomainId())) { throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to update load balancer rule, permission denied."); } } long jobId = getManagementServer().updateLoadBalancerRuleAsync(userId, lb.getAccountId(), lb.getId().longValue(), name, description, privatePort, algorithm); List> returnValues = new ArrayList>(); returnValues.add(new Pair(BaseCmd.Properties.JOB_ID.getName(), Long.valueOf(jobId).toString())); return returnValues; } }