-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CHANGE] Refactor shard assignment from service to Project #147
There are cases when a single service contains enough projects that it outgrows a single shard. Since service.name is unique, we could not use the same service.name on multiple shards. Refactoring Shard assignment to a Project gives us more flexibility for managing our Projects, and changes Service to a grouping of related rules and notifications Service.shard is moved to Project.shard Service block groups Projects by Shard Service list gets pagination. It's expected that in the default case, users will subscribe to their projects updates, and therefore see them on the home page
- Loading branch information
Showing
38 changed files
with
663 additions
and
483 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Generated by Django 2.1.8 on 2019-04-22 07:15 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
def project_to_shard(apps, schema_editor): | ||
Project = apps.get_model("promgen", "Project") | ||
for project in Project.objects.all(): | ||
project.shard_id = project.service.shard_id | ||
project.save() | ||
|
||
|
||
def project_to_service(apps, schema_editor): | ||
Project = apps.get_model("promgen", "Project") | ||
for project in Project.objects.all(): | ||
project.service.shard_id = project.shard_id | ||
project.service.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [("promgen", "0007_message_filter")] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="project", | ||
name="shard", | ||
field=models.ForeignKey( | ||
default=1, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="promgen.Shard", | ||
), | ||
preserve_default=False, | ||
), | ||
migrations.RunPython(project_to_shard, project_to_service), | ||
migrations.AlterModelOptions(name="service", options={"ordering": ["name"]}), | ||
migrations.RemoveField(model_name="service", name="shard"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,68 @@ | ||
{% extends "base.html" %} | ||
{% load i18n %} | ||
{% load promgen %} | ||
|
||
{% block content %} | ||
|
||
<div class="page-header"> | ||
<h1>Farms</h1> | ||
</div> | ||
|
||
<ol class="breadcrumb"> | ||
<li><a href="{% url 'service-list' %}">Home</a></li> | ||
<li class="active">All Farms</li> | ||
</ol> | ||
{% breadcrumb label="Farms" %} | ||
|
||
{% include "promgen/pagination.html" %} | ||
|
||
<div class="panel panel-default"> | ||
<table class="table table-bordered table-condensed"> | ||
<thead> | ||
<tr> | ||
<th>Farm</th> | ||
<th>Source</th> | ||
<th>Hosts</th> | ||
<th>Project</th> | ||
<th> </th> | ||
</tr> | ||
</thead> | ||
{% for farm in farm_list %} | ||
<table class="table table-bordered table-condensed"> | ||
<thead> | ||
<tr> | ||
<td><a href="{% url 'farm-detail' farm.id %}">{{ farm.name }}</a></td> | ||
<td> | ||
{% if farm.driver.remote %} | ||
<span class="glyphicon glyphicon-cloud-download" aria-hidden="true"></span> | ||
{% endif %} | ||
{{ farm.source }} | ||
</td> | ||
<td> | ||
<ul> | ||
{% for host in farm.host_set.all %} | ||
<li><a href="{% url 'host-detail' host.name %}">{{ host.name }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
</td> | ||
<td> | ||
<ul> | ||
<th>Farm</th> | ||
<th>Source</th> | ||
<th>Hosts</th> | ||
<th>Project</th> | ||
<th> </th> | ||
</tr> | ||
</thead> | ||
{% for farm in farm_list %} | ||
<tr> | ||
<td><a href="{% url 'farm-detail' farm.id %}">{{ farm.name }}</a></td> | ||
<td> | ||
{% if farm.driver.remote %} | ||
<span class="glyphicon glyphicon-cloud-download" aria-hidden="true"></span> | ||
{% endif %} | ||
{{ farm.source }} | ||
</td> | ||
<td> | ||
<ul> | ||
{% for host in farm.host_set.all %} | ||
<li><a href="{% url 'host-detail' host.name %}">{{ host.name }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
</td> | ||
<td> | ||
<ul> | ||
{% for project in farm.project_set.all %} | ||
<li><a href="{% url 'project-detail' project.id %}">{{ project.name }}</a></li> | ||
<li><a href="{% url 'project-detail' project.id %}">{{ project.name }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
</td> | ||
<td> | ||
{% if farm.driver.remote %} | ||
<form method="post" action="{% url 'farm-convert' farm.id %}" onsubmit="return confirm('Convert this farm to local?')" style="display: inline"> | ||
{% csrf_token %} | ||
<button class="btn btn-warning">{% trans "Convert to Local Farm" %}</button> | ||
</form> | ||
{% endif %} | ||
<form method="post" action="{% url 'farm-delete' farm.id %}" onsubmit="return confirm('Delete this farm?')" style="display: inline"> | ||
{% csrf_token %} | ||
<button class="btn btn-danger">{% trans "Delete" %}</button> | ||
</form> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
|
||
</ul> | ||
</td> | ||
<td> | ||
{% if farm.driver.remote %} | ||
<form method="post" action="{% url 'farm-convert' farm.id %}" onsubmit="return confirm('Convert this farm to local?')" style="display: inline"> | ||
{% csrf_token %} | ||
<button class="btn btn-warning">{% trans "Convert to Local Farm" %}</button> | ||
</form> | ||
{% endif %} | ||
<form method="post" action="{% url 'farm-delete' farm.id %}" onsubmit="return confirm('Delete this farm?')" style="display: inline"> | ||
{% csrf_token %} | ||
<button class="btn btn-danger">{% trans "Delete" %}</button> | ||
</form> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
</div> | ||
|
||
{% include "promgen/pagination.html" %} | ||
|
||
{% endblock %} |
Oops, something went wrong.