Skip to content

Commit

Permalink
Tracking pull request to merge release-1.15.0.1 to master (#424)
Browse files Browse the repository at this point in the history
Fix site slowness issue, update configmap mount location on frontend and correct prod logoff url
  • Loading branch information
kuanfandevops authored Dec 10, 2020
1 parent f27f6c1 commit 16cb7df
Show file tree
Hide file tree
Showing 39 changed files with 612 additions and 383 deletions.
6 changes: 3 additions & 3 deletions .pipeline-v3/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const phases = {
dev: {namespace:'tbiwaq-dev', transient:true, name: `${name}`, ssoSuffix:'-dev',
ssoName:'dev.oidc.gov.bc.ca', phase: 'dev' , changeId:`${changeId}`, suffix: `-dev-${changeId}`,
instance: `${name}-dev-${changeId}` , version:`${version}-${changeId}`, tag:`dev-${version}-${changeId}`,
host: `zeva-dev-${changeId}.${ocpName}.gov.bc.ca`, djangoDebug: 'True',
host: `zeva-dev-${changeId}.${ocpName}.gov.bc.ca`, djangoDebug: 'True', logoutHost: 'logontest.gov.bc.ca',
frontendCpuRequest: '100m', frontendCpuLimit: '700m', frontendMemoryRequest: '300M', frontendMemoryLimit: '4G', frontendReplicas: 1,
backendCpuRequest: '300m', backendCpuLimit: '600m', backendMemoryRequest: '1G', backendMemoryLimit: '2G', backendHealthCheckDelay: 30, backendHost: `zeva-backend-dev-${changeId}.${ocpName}.gov.bc.ca`, backendReplicas: 1,
minioCpuRequest: '100m', minioCpuLimit: '200m', minioMemoryRequest: '200M', minioMemoryLimit: '500M', minioPvcSize: '1G',
Expand All @@ -25,7 +25,7 @@ const phases = {
test: {namespace:'tbiwaq-test', name: `${name}`, ssoSuffix:'-test',
ssoName:'test.oidc.gov.bc.ca', phase: 'test' , changeId:`${changeId}`, suffix: `-test`,
instance: `${name}-test`, version:`${version}`, tag:`test-${version}`,
host: `zeva-test.${ocpName}.gov.bc.ca`, djangoDebug: 'False',
host: `zeva-test.${ocpName}.gov.bc.ca`, djangoDebug: 'False', logoutHost: 'logontest.gov.bc.ca',
frontendCpuRequest: '300m', frontendCpuLimit: '600m', frontendMemoryRequest: '500M', frontendMemoryLimit: '1G', frontendReplicas: 2, frontendMinReplicas: 2, frontendMaxReplicas: 5,
backendCpuRequest: '100m', backendCpuLimit: '500m', backendMemoryRequest: '500M', backendMemoryLimit: '2G', backendHealthCheckDelay: 30, backendReplicas: 1, backendMinReplicas: 2, backendMaxReplicas: 5, backendHost: `zeva-backend-test.${ocpName}.gov.bc.ca`,
minioCpuRequest: '100m', minioCpuLimit: '300m', minioMemoryRequest: '500M', minioMemoryLimit: '700M', minioPvcSize: '5G',
Expand All @@ -36,7 +36,7 @@ const phases = {
prod: {namespace:'tbiwaq-prod', name: `${name}`, ssoSuffix:'',
ssoName:'oidc.gov.bc.ca', phase: 'prod' , changeId:`${changeId}`, suffix: `-prod`,
instance: `${name}-prod`, version:`${version}`, tag:`prod-${version}`,
host: `zeroemissionvehicles.${ocpName}.gov.bc.ca`, djangoDebug: 'False',
host: `zeroemissionvehicles.${ocpName}.gov.bc.ca`, djangoDebug: 'False', logoutHost: 'logon7.gov.bc.ca',
frontendCpuRequest: '300m', frontendCpuLimit: '600m', frontendMemoryRequest: '1G', frontendMemoryLimit: '2G', frontendReplicas: 2, frontendMinReplicas: 2, frontendMaxReplicas: 5,
backendCpuRequest: '200m', backendCpuLimit: '700m', backendMemoryRequest: '1G', backendMemoryLimit: '2G', backendHealthCheckDelay: 30, backendReplicas: 1, backendMinReplicas: 2, backendMaxReplicas: 5, backendHost: `zeva-backend-prod.${ocpName}.gov.bc.ca`,
minioCpuRequest: '100m', minioCpuLimit: '300m', minioMemoryRequest: '500M', minioMemoryLimit: '700M', minioPvcSize: '10G',
Expand Down
3 changes: 2 additions & 1 deletion .pipeline-v3/lib/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ module.exports = settings => {
'SSO_NAME': phases[phase].ssoName,
'KEYCLOAK_REALM': 'rzh2zkjq',
'DJANGO_DEBUG': phases[phase].djangoDebug,
'OCP_NAME': phases[phase].ocpName
'OCP_NAME': phases[phase].ocpName,
'LOGOUT_HOST': phases[phase].logoutHost
}
}))

Expand Down
4 changes: 2 additions & 2 deletions .pipeline/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const phases = {
minioCpuRequest: '100m', minioCpuLimit: '300m', minioMemoryRequest: '500M', minioMemoryLimit: '700M', minioPvcSize: '5G',
schemaspyCpuRequest: '20m', schemaspyCpuLimit: '200m', schemaspyMemoryRequest: '150M', schemaspyMemoryLimit: '300M', schemaspyHealthCheckDelay: 160,
rabbitmqCpuRequest: '250m', rabbitmqCpuLimit: '700m', rabbitmqMemoryRequest: '500M', rabbitmqMemoryLimit: '700M', rabbitmqPvcSize: '1G', rabbitmqReplica: 2, rabbitmqPostStartSleep: 120, storageClass: 'netapp-block-standard',
patroniCpuRequest: '500m', patroniCpuLimit: '1000m', patroniMemoryRequest: '500M', patroniMemoryLimit: '1G', patroniPvcSize: '40G', patroniReplica: 2, storageClass: 'netapp-block-standard', ocpName: `${ocpName}`},
patroniCpuRequest: '500m', patroniCpuLimit: '1000m', patroniMemoryRequest: '500M', patroniMemoryLimit: '1G', patroniPvcSize: '5G', patroniReplica: 2, storageClass: 'netapp-block-standard', ocpName: `${ocpName}`},

prod: {namespace:'e52f12-prod', name: `${name}`, ssoSuffix:'',
ssoName:'oidc.gov.bc.ca', phase: 'prod' , changeId:`${changeId}`, suffix: `-prod`,
Expand All @@ -42,7 +42,7 @@ const phases = {
minioCpuRequest: '100m', minioCpuLimit: '300m', minioMemoryRequest: '500M', minioMemoryLimit: '700M', minioPvcSize: '10G',
schemaspyCpuRequest: '50m', schemaspyCpuLimit: '400m', schemaspyMemoryRequest: '150M', schemaspyMemoryLimit: '300M', schemaspyHealthCheckDelay: 160,
rabbitmqCpuRequest: '250m', rabbitmqCpuLimit: '700m', rabbitmqMemoryRequest: '500M', rabbitmqMemoryLimit: '1G', rabbitmqPvcSize: '5G', rabbitmqReplica: 2, rabbitmqPostStartSleep: 120, storageClass: 'netapp-block-standard',
patroniCpuRequest: '500m', patroniCpuLimit: '1000m', patroniMemoryRequest: '1G', patroniMemoryLimit: '2G', patroniPvcSize: '50G', patroniReplica: 3, storageClass: 'netapp-block-standard', ocpName: `${ocpName}`},
patroniCpuRequest: '500m', patroniCpuLimit: '1000m', patroniMemoryRequest: '1G', patroniMemoryLimit: '2G', patroniPvcSize: '30G', patroniReplica: 3, storageClass: 'netapp-block-standard', ocpName: `${ocpName}`},

};

Expand Down
16 changes: 8 additions & 8 deletions .yo-rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
"path": ".",
"environments": {
"build": {
"namespace": "tbiwaq-tools"
"namespace": "f52f12-tools"
},
"dev": {
"namespace": "tbiwaq-dev"
"namespace": "f52f12-dev"
},
"test": {
"namespace": "tbiwaq-test"
"namespace": "f52f12-test"
},
"prod": {
"namespace": "tbiwaq-prod"
"namespace": "f52f12-prod"
}
},
"jenkinsJobName": "zeva",
Expand All @@ -29,17 +29,17 @@
"jenkins": {
"path": ".jenkins",
"name": "jenkins",
"namespace": "tbiwaq-tools",
"namespace": "f52f12-tools",
"version": "1.0.0",
"environments": {
"build": {
"namespace": "tbiwaq-tools"
"namespace": "f52f12-tools"
},
"dev": {
"namespace": "tbiwaq-tools"
"namespace": "f52f12-tools"
},
"prod": {
"namespace": "tbiwaq-tools"
"namespace": "f52f12-tools"
}
},
"jenkinsJobName": "_jenkins",
Expand Down
54 changes: 0 additions & 54 deletions .yo-rc.json-v4

This file was deleted.

7 changes: 6 additions & 1 deletion backend/api/serializers/credit_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,12 @@ def create(self, validated_data):
signing_authority_assertion_id=confirmation
)

serializer = CreditTransferSerializer(credit_transfer, read_only=True)
serializer = CreditTransferSerializer(
credit_transfer, read_only=True,
context={
'request': request
}
)

return serializer.data

Expand Down
111 changes: 84 additions & 27 deletions backend/api/serializers/sales_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,27 @@ class SalesSubmissionListSerializer(
validation_status = SerializerMethodField()
submission_history = SerializerMethodField()

def get_submission_history(self, obj):
request = self.context.get('request')
if not request.user.is_government and obj.validation_status in [
SalesSubmissionStatuses.RECOMMEND_REJECTION,
SalesSubmissionStatuses.RECOMMEND_APPROVAL,
SalesSubmissionStatuses.CHECKED,
]:
# return the date that it was submitted
history = SalesSubmissionHistory.objects.filter(
submission_id=obj.id,
validation_status=SalesSubmissionStatuses.SUBMITTED
).order_by('update_timestamp').first()
return history.update_timestamp.date()
# return the last updated date
history = SalesSubmissionHistory.objects.filter(
submission_id=obj.id,
validation_status=obj.validation_status
).order_by('update_timestamp').first()
return history.update_timestamp.date()


def get_submission_history(self, obj):
request = self.context.get('request')
if not request.user.is_government and obj.validation_status in [
Expand Down Expand Up @@ -173,9 +194,7 @@ def get_total_warnings(self, obj):
]

if obj.validation_status in valid_statuses:
for row in obj.content.all():
if len(row.warnings) > 0 and row.record_of_sale is None:
warnings += 1
warnings = obj.unselected

return warnings

Expand All @@ -192,22 +211,6 @@ class Meta:
'total_credits', 'total_warnings', 'unselected',
)


class SalesSubmissionHistorySerializer(
ModelSerializer, EnumSupportSerializerMixin, BaseSerializer
):
create_user = SerializerMethodField()
update_user = SerializerMethodField()
validation_status = SerializerMethodField()

class Meta:
model = SalesSubmissionHistory
fields = (
'create_timestamp', 'create_user',
'validation_status', 'update_user'
)


class SalesSubmissionSerializer(
ModelSerializer, EnumSupportSerializerMixin,
BaseSerializer
Expand Down Expand Up @@ -353,6 +356,31 @@ class Meta:
)


class SalesSubmissionDetailSerializer(
ModelSerializer, EnumSupportSerializerMixin,
BaseSerializer
):
content = SerializerMethodField()

def get_content(self, instance):
request = self.context.get('request')

serializer = SalesSubmissionContentSerializer(
instance.content,
read_only=True,
many=True,
context={'request': request}
)

return serializer.data

class Meta:
model = SalesSubmission
fields = (
'id', 'validation_status', 'content', 'submission_id'
)


class SalesSubmissionSaveSerializer(
ModelSerializer
):
Expand All @@ -372,7 +400,7 @@ def validate_validation_status(self, value):

def update(self, instance, validated_data):
request = self.context.get('request')
records = request.data.get('records')
invalidated = request.data.get('invalidated', None)
sales_submission_comment = validated_data.pop('sales_submission_comment', None)

if sales_submission_comment:
Expand All @@ -382,15 +410,44 @@ def update(self, instance, validated_data):
comment=sales_submission_comment.get('comment')
)

if records is not None:
if invalidated is not None:
RecordOfSale.objects.filter(submission_id=instance.id).delete()
valid_vehicles = Vehicle.objects.filter(
organization_id=instance.organization_id,
validation_status=VehicleDefinitionStatuses.VALIDATED
).values_list('model_year__name', Upper('make'), 'model_name')

duplicate_vins = SalesSubmissionContent.objects.annotate(
vin_count=Count('xls_vin')
).filter(
submission_id=instance.id,
vin_count__gt=1
).values_list('xls_vin', flat=True)

awarded_vins = RecordOfSale.objects.exclude(
submission_id=instance.id
).values_list('vin', flat=True)

content = SalesSubmissionContent.objects.filter(
submission_id=instance.id
).exclude(
id__in=invalidated
).exclude(
xls_vin__in=awarded_vins
).exclude(
xls_vin__in=duplicate_vins,
xls_sale_date__lte="43102.0"
)

for record_id in records:
row = SalesSubmissionContent.objects.filter(
id=record_id
).first()
for row in content:
try:
model_year = int(float(row.xls_model_year))
except ValueError:
model_year = 0

if row and row.vehicle:
if (
str(model_year), row.xls_make.upper(), row.xls_model,
) in valid_vehicles:
RecordOfSale.objects.create(
sale_date=get_date(
row.xls_sale_date,
Expand All @@ -408,7 +465,7 @@ def update(self, instance, validated_data):

if validation_status:
SalesSubmissionHistory.objects.create(
submission=instance,
submission_id=instance.id,
validation_status=validation_status,
update_user=request.user.username,
create_user=request.user.username,
Expand Down
26 changes: 12 additions & 14 deletions backend/api/services/credit_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from api.models.vehicle import Vehicle
from api.models.weight_class import WeightClass
from api.services.credit_transfer import aggregate_credit_transfer_details
from django.core.exceptions import ValidationError


def award_credits(submission):
records = RecordOfSale.objects.filter(
Expand Down Expand Up @@ -182,19 +184,17 @@ def validate_transfer(transfer):
weight_type = each.weight_class.id
# check if supplier has enough for this transfer
for record in supplier_totals:
if (record['model_year_id'] == model_year and record['credit_class_id'] == credit_type
and record['weight_class_id'] == weight_type):
print(record['total_value'])
found = True
record['total_value'] -= credit_value
print(record)
if record['total_value'] < 0:
print('NOT ENOUGH CREDITS')
has_enough = False
if (record['model_year_id'] == model_year and record[
'credit_class_id'] == credit_type
and record['weight_class_id'] == weight_type):
found = True
record['total_value'] -= credit_value
if record['total_value'] < 0:
has_enough = False
if not found:
has_enough = False
if not has_enough:
raise Exception('not enough credits')
raise ValidationError('not enough credits')
else:
# add to each dictionary (one broken down by years and the other not)
if credit_type not in credit_total_no_years:
Expand Down Expand Up @@ -223,7 +223,8 @@ def validate_transfer(transfer):
),
total_value=1 * credit_value,
update_user=transfer.update_user,
weight_class_id=1
weight_class=WeightClass.objects.get(
weight_class_code='LDV')
)
for each_supplier in [initiating_supplier, recieving_supplier]:
reduce_total = each_supplier == transfer.debit_from
Expand Down Expand Up @@ -259,6 +260,3 @@ def validate_transfer(transfer):
credit_transaction=added_transaction,
organization_id=each_supplier.id
)



Loading

0 comments on commit 16cb7df

Please sign in to comment.