Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add drop down menu for showing main account and sub account #1240

Merged
merged 32 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6b1b776
add drop down menu for showing main account and sub account
liyaqin1 Aug 23, 2023
2b284f0
missed an import
liyaqin1 Aug 23, 2023
8ebd7b7
missed an argument
liyaqin1 Aug 23, 2023
6ea1045
missed something in the query path
liyaqin1 Aug 23, 2023
7d2a956
debug
liyaqin1 Aug 23, 2023
295c884
debug
liyaqin1 Aug 23, 2023
eab0086
show the hosts correctly
liyaqin1 Aug 23, 2023
be16f76
improve the ui
liyaqin1 Aug 23, 2023
8f05216
update another place
liyaqin1 Aug 23, 2023
50ddae6
consider no account id situation
liyaqin1 Aug 23, 2023
68485ed
debug
liyaqin1 Aug 23, 2023
a89109b
debug
liyaqin1 Aug 23, 2023
9d5c787
generate host_id and account_id map for each env/stage
liyaqin1 Aug 24, 2023
e49ccf4
debug
liyaqin1 Aug 24, 2023
16fb2eb
debug
liyaqin1 Aug 24, 2023
4bea711
debug
liyaqin1 Aug 24, 2023
b3d6550
debug
liyaqin1 Aug 24, 2023
38e9c24
use agent helper instead of environs helper
liyaqin1 Aug 24, 2023
b7e413a
test
liyaqin1 Aug 24, 2023
e1d168d
debug
liyaqin1 Aug 24, 2023
b07ed7e
debug
liyaqin1 Aug 24, 2023
21c18da
debug
liyaqin1 Aug 24, 2023
583c7f2
debug
liyaqin1 Aug 24, 2023
27a9661
debug
liyaqin1 Aug 24, 2023
3976da8
debug
liyaqin1 Aug 24, 2023
5093b21
debug
liyaqin1 Aug 24, 2023
e6dedf8
debug
liyaqin1 Aug 24, 2023
0567bb1
debug
liyaqin1 Aug 24, 2023
d3fb7d6
debug
liyaqin1 Aug 24, 2023
32f99e4
call an existing api to get host_id and account_id mapping
liyaqin1 Aug 24, 2023
4bb14ab
use string instead of int to compare
liyaqin1 Aug 24, 2023
0aadfa2
remove unnecessary code
liyaqin1 Aug 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,69 @@
{% for agentStat in report.agentStats %}
{% for hostTag in hostTags %}
{% if agentStat.agent.hostName == hostTag.hostName %}
{% if report.showMode == "complete" or report.showMode == "compact" %}
<a href="/env/{{env.envName}}/{{env.stageName}}/host/{{ agentStat.agent.hostName }}"
type="button" class="deployToolTip btn btn-xs {{ agentStat | agentButton }} host-btn"
title="{{ agentStat | agentTip }}">
{% if report.showMode == "complete" %}
<small>{{ agentStat.agent.hostName }}</small>
{% endif %}
<i class="fa fa-fw {{ agentStat | agentIcon }}"></i>
type="button" class="deployToolTip btn btn-xs {{ agentStat | agentButton }} host-btn"
title="{{ agentStat | agentTip }}">
{% if report.showMode != "compact" %}
<small>{{ agentStat.agent.hostName }}</small>
{% endif %}
<i class="fa fa-fw {{ agentStat | agentIcon }}"></i>
</a>
{% elif report.showMode == "primaryAcct" %}

<a href="/env/{{env.envName}}/{{env.stageName}}/host/{{ agentStat.agent.hostName }}"
type="button" class="deployToolTip btn btn-xs {{ agentStat | agentButton }} host-btn"
title="{{ agentStat | agentTip }}">
<small>{{ agentStat.agent.hostName }}</small>
<i class="fa fa-fw {{ agentStat | agentIcon }}"></i>
</a>

{% elif report.showMode == "subAcct" %}

<a href="/env/{{env.envName}}/{{env.stageName}}/host/{{ agentStat.agent.hostName }}"
type="button" class="deployToolTip btn btn-xs {{ agentStat | agentButton }} host-btn"
title="{{ agentStat | agentTip }}">
<small>{{ agentStat.agent.hostName }}</small>
<i class="fa fa-fw {{ agentStat | agentIcon }}"></i>
</a>

{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
</div>
{% endfor %}
{% else %}
{% for agentStat in report.agentStats %}
<a href="/env/{{env.envName}}/{{env.stageName}}/host/{{ agentStat.agent.hostName }}"
{% if report.showMode == "complete" or report.showMode == "compact" %}
<a href="/env/{{env.envName}}/{{env.stageName}}/host/{{ agentStat.agent.hostName }}"
type="button" class="deployToolTip btn btn-xs {{ agentStat | agentButton }} host-btn"
title="{{ agentStat | agentTip }}">
{% if report.showMode == "complete" %}
{% if report.showMode != "compact" %}
<small>{{ agentStat.agent.hostName }}</small>
{% endif %}
<i class="fa fa-fw {{ agentStat | agentIcon }}"></i>
</a>
</a>
{% elif report.showMode == "primaryAcct" %}
{% if agentStat.agent.hostId == 'i-0ce811ae17e6c1b78' %}
liyaqin1 marked this conversation as resolved.
Show resolved Hide resolved
<a href="/env/{{env.envName}}/{{env.stageName}}/host/{{ agentStat.agent.hostName }}"
type="button" class="deployToolTip btn btn-xs {{ agentStat | agentButton }} host-btn"
title="{{ agentStat | agentTip }}">
<small>{{ agentStat.agent.hostName }}</small>
<i class="fa fa-fw {{ agentStat | agentIcon }}"></i>
</a>
{% endif %}
{% elif report.showMode == "subAcct" %}
{% if accountIds['i-0a6485b3eed813298'] == 998131032990 %}
liyaqin1 marked this conversation as resolved.
Show resolved Hide resolved
<a href="/env/{{env.envName}}/{{env.stageName}}/host/{{ agentStat.agent.hostName }}"
type="button" class="deployToolTip btn btn-xs {{ agentStat | agentButton }} host-btn"
title="{{ agentStat | agentTip }}">
<small>{{ agentStat.agent.hostName }}</small>
<i class="fa fa-fw {{ agentStat | agentIcon }}"></i>
</a>
{% endif %}
{% endif %}
{% endfor %}
{% endif %}

Expand Down
18 changes: 18 additions & 0 deletions deploy-board/deploy_board/templates/environs/env_landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,24 @@ <h4 class="panel-title pull-left pointer-cursor">
> Complete
</label></div>
</li>
<li>
<div class="radio"><label>&nbsp;
<input type="radio" name="showMode" value="primaryAcct"
{% if report.showMode == "primaryAcct" %}
checked
{% endif %}
> Primary Account
</label></div>
</li>
<li>
<div class="radio"><label>&nbsp;
<input type="radio" name="showMode" value="subAcct"
{% if report.showMode == "subAcct" %}
checked
{% endif %}
> Sub Account
</label></div>
</li>
<li role="presentation" class="divider"></li>
<li>
<div class="checkbox"><label>&nbsp;
Expand Down
2 changes: 2 additions & 0 deletions deploy-board/deploy_board/webapp/env_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,14 @@ def get(self, request, name, stage=None):
report = agent_report.gen_report(request, env, progress, sortByStatus=sortByStatus)
report.showMode = showMode
report.sortByStatus = sortByStatus
accountIds = agents_helper.get_accountIds_by_env(request, env['id'])
context = {
"envs": envs,
"env": env,
"env_promote": env_promote,
"stages": stages,
"report": report,
"accountIds": json.dumps(accountIds),
"has_deploy": True,
"metrics": metrics,
"metrics_dashboard_only": metrics_dashboard_only,
Expand Down
4 changes: 4 additions & 0 deletions deploy-board/deploy_board/webapp/helpers/agents_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ def get_agents_by_host(request, host_name):

def get_agents_total_by_env(request, env_id):
return deployclient.get("/agents/env/%s/total" % env_id, request.teletraan_user_id.token)


def get_accountIds_by_env(request, env_id):
return deployclient.get("/agents/env/%s/accountIds" % env_id, request.teletraan_user_id.token)
2 changes: 1 addition & 1 deletion deploy-board/deploy_board/webapp/helpers/hosts_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@


def get_hosts_by_name(request, host_name):
return deployclient.get("/hosts/%s" % host_name, request.teletraan_user_id.token)
return deployclient.get("/hosts/%s" % host_name, request.teletraan_user_id.token)
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,6 @@ public interface HostDAO {
Collection<String> getTerminatingHostIdsByGroup(String groupName) throws Exception;

String getAccountIdByHost(String hostName) throws Exception;

String getAccountIdByHostId(String hostId) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class DBHostDAOImpl implements HostDAO {
private static final String GET_NEW_HOSTIDS_BY_GROUP = "SELECT DISTINCT host_id FROM hosts WHERE can_retire=0 AND group_name=? AND state not in (?,?,?)";
private static final String GET_TERMINATING_HOST_IDS_BY_GROUP = "SELECT DISTINCT host_id FROM hosts WHERE state in (?, ?, ?) AND group_name=?";
private static final String GET_ACCOUNTID_BY_HOSTNAME = "SELECT DISTINCT account_id FROM hosts WHERE host_name=?";
private static final String GET_ACCOUNTID_BY_HOSTID = "SELECT DISTINCT account_id FROM hosts WHERE host_id=?";

private BasicDataSource dataSource;

Expand Down Expand Up @@ -294,4 +295,10 @@ public String getAccountIdByHost(String hostName) throws Exception {
return new QueryRunner(dataSource).query(GET_ACCOUNTID_BY_HOSTNAME,
SingleResultSetHandlerFactory.<String>newObjectHandler(), hostName);
}

@Override
public String getAccountIdByHostId(String hostId) throws Exception {
return new QueryRunner(dataSource).query(GET_ACCOUNTID_BY_HOSTID,
SingleResultSetHandlerFactory.<String>newObjectHandler(), hostId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import com.pinterest.deployservice.bean.AgentBean;
import com.pinterest.deployservice.dao.AgentDAO;
import com.pinterest.deployservice.dao.HostDAO;

import com.pinterest.teletraan.TeletraanServiceContext;

import org.slf4j.Logger;
Expand All @@ -32,6 +34,8 @@

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

@Path("/v1/agents")
@Api(tags = "Agents")
Expand All @@ -45,9 +49,11 @@
public class Agents {
private static final Logger LOG = LoggerFactory.getLogger(Agents.class);
private AgentDAO agentDAO;
private HostDAO hostDAO;

public Agents(TeletraanServiceContext context) {
agentDAO = context.getAgentDAO();
hostDAO = context.getHostDAO();
}

@GET
Expand Down Expand Up @@ -89,4 +95,23 @@ public long getCountByEnvName(
public long getCountTotalHosts() throws Exception {
return agentDAO.countDeployedHosts();
}

@GET
@Path("/env/{envId : [a-zA-Z0-9\\-_]+}/accountIds")
@ApiOperation(
value = "Get account id for a specific environment object",
notes = "Returns a mapping object of host id and account id given an environment id",
response = String.class, responseContainer = "Map")
public Map<String, String> getAccountIds(
@ApiParam(value = "Environment id", required = true)@PathParam("envId") String envId) throws Exception {
Map<String, String> result = new HashMap<String, String>();
List<AgentBean> agents = agentDAO.getAllByEnv(envId);
for (int i = 0; i < agents.size(); i++)
liyaqin1 marked this conversation as resolved.
Show resolved Hide resolved
{
String hostId = agents.get(i).getHost_id();
liyaqin1 marked this conversation as resolved.
Show resolved Hide resolved
String accountId = hostDAO.getAccountIdByHostId(hostId);
result.put(hostId, accountId);
}
return result;
}
}
Loading