Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #820 from joyent/ether/v3-small-db-changes
Browse files Browse the repository at this point in the history
v3: small db changes
  • Loading branch information
karenetheridge authored Jul 2, 2019
2 parents 23a84e6 + 8a624e5 commit 05b0357
Show file tree
Hide file tree
Showing 52 changed files with 293 additions and 247 deletions.
7 changes: 7 additions & 0 deletions docs/modules/Conch::DB::Result::HardwareProduct.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ data_type: 'text'
is_nullable: 1
```

## rack\_unit\_size

```
data_type: 'integer'
is_nullable: 0
```

# PRIMARY KEY

- ["id"](#id)
Expand Down
7 changes: 0 additions & 7 deletions docs/modules/Conch::DB::Result::HardwareProductProfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ is_nullable: 0
size: 16
```

## rack\_unit

```
data_type: 'integer'
is_nullable: 0
```

## purpose

```
Expand Down
2 changes: 0 additions & 2 deletions docs/modules/Conch::DB::Result::Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ Conch::DB::Result::Migration

```
data_type: 'integer'
is_auto_increment: 1
is_nullable: 0
sequence: 'migration_id_seq'
```

## created
Expand Down
8 changes: 0 additions & 8 deletions docs/modules/Conch::DB::Result::UserWorkspaceRole.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ is_nullable: 0
- ["user\_id"](#user_id)
- ["workspace\_id"](#workspace_id)

# UNIQUE CONSTRAINTS

## `user_workspace_role_user_id_workspace_id_role_key`

- ["user\_id"](#user_id)
- ["workspace\_id"](#workspace_id)
- ["role"](#role)

# RELATIONS

## user\_account
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/Conch::DB::Result::Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Conch::DB::Result::Validation

```
data_type: 'uuid'
default_value: uuid_generate_v4()
default_value: gen_random_uuid()
is_nullable: 0
size: 16
```
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/Conch::DB::Result::ValidationPlan.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Conch::DB::Result::ValidationPlan

```
data_type: 'uuid'
default_value: uuid_generate_v4()
default_value: gen_random_uuid()
is_nullable: 0
size: 16
```
Expand Down
6 changes: 3 additions & 3 deletions docs/modules/Conch::DB::Result::ValidationResult.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Conch::DB::Result::ValidationResult

```
data_type: 'uuid'
default_value: uuid_generate_v4()
default_value: gen_random_uuid()
is_nullable: 0
size: 16
```
Expand Down Expand Up @@ -61,7 +61,7 @@ is_nullable: 1

```perl
data_type: 'enum'
extra: {custom_type_name => "validation_status_enum",list => ["error","fail","processing","pass"]}
extra: {custom_type_name => "validation_status_enum",list => ["error","fail","pass"]}
is_nullable: 0
```

Expand All @@ -72,7 +72,7 @@ data_type: 'text'
is_nullable: 0
```

## component\_id
## component

```
data_type: 'text'
Expand Down
6 changes: 3 additions & 3 deletions docs/modules/Conch::DB::Result::ValidationState.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Conch::DB::Result::ValidationState

```
data_type: 'uuid'
default_value: uuid_generate_v4()
default_value: gen_random_uuid()
is_nullable: 0
size: 16
```
Expand Down Expand Up @@ -47,15 +47,15 @@ original: {default_value => \"now()"}

```perl
data_type: 'enum'
extra: {custom_type_name => "validation_status_enum",list => ["error","fail","processing","pass"]}
extra: {custom_type_name => "validation_status_enum",list => ["error","fail","pass"]}
is_nullable: 0
```

## completed

```
data_type: 'timestamp with time zone'
is_nullable: 1
is_nullable: 0
```

## device\_report\_id
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/Conch::DB::Result::Workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Conch::DB::Result::Workspace

```
data_type: 'uuid'
default_value: uuid_generate_v4()
default_value: gen_random_uuid()
is_nullable: 0
size: 16
```
Expand Down
10 changes: 5 additions & 5 deletions docs/modules/Conch::Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ You may also provide the following attributes to override validation results
attribute.

This value is not stored in the database. To disambiguate multiple results in the database, use
`component_id`.
`component`.

```perl
$self->register_result(
Expand Down Expand Up @@ -314,16 +314,16 @@ You may also provide the following attributes to override validation results
);
```

- `component_id`
- `component`

You may specify the optional string attribute `component_id` to set an
You may specify the optional string attribute `component` to set an
identifier to help identify a specific component under test.

```perl
$self->register_result(
expected => 'OK',
got => $disk->{health},
component_id => $disk->{serial_number}
component => $disk->{serial_number}
);
```

Expand Down Expand Up @@ -370,7 +370,7 @@ $self->fail('This validation fails but validation evaluation will continue')
unless defined($data->{required_value});
```

The attributes `name`, `category`, `component_id`, and `hint` may be
The attributes `name`, `category`, `component`, and `hint` may be
specified like with ["register\_result"](#register_result).

```perl
Expand Down
2 changes: 0 additions & 2 deletions json-schema/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ definitions:
description: corresponds to validation_status_enum in the database
type: string
enum:
# TODO: remove antiquated 'processing'
- error
- fail
- processing
- pass
non_empty_string:
type: string
Expand Down
6 changes: 3 additions & 3 deletions json-schema/request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ definitions:
- name
- alias
- hardware_vendor_id
- rack_unit_size
- type: object
properties:
hardware_product_profile:
Expand All @@ -217,8 +218,6 @@ definitions:
additionalProperties: false
minProperties: 1
properties:
rack_unit:
$ref: common.yaml#/definitions/positive_integer
purpose:
type: string
bios_firmware:
Expand Down Expand Up @@ -335,13 +334,14 @@ definitions:
oneOf:
- type: string
- type: 'null'
rack_unit_size:
$ref: common.yaml#/definitions/positive_integer
hardware_product_profile:
$ref: /definitions/HardwareProductProfileUpdate
HardwareProductProfileCreate:
allOf:
- $ref: /definitions/HardwareProductProfileUpdate
- required:
- rack_unit
- purpose
- bios_firmware
- cpu_num
Expand Down
22 changes: 9 additions & 13 deletions json-schema/response.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ definitions:
- legacy_product_name
- sku
- specification
- rack_unit_size
- hardware_product_profile
- created
- updated
Expand Down Expand Up @@ -735,6 +736,8 @@ definitions:
oneOf:
- type: string
- type: 'null'
rack_unit_size:
$ref: common.yaml#/definitions/positive_integer
hardware_product_profile:
oneOf:
- $ref: /definitions/HardwareProductProfile
Expand All @@ -758,7 +761,6 @@ definitions:
- nics_num
- psu_total
- purpose
- rack_unit
- ram_total
- sas_hdd_num
- sas_hdd_size
Expand Down Expand Up @@ -800,8 +802,6 @@ definitions:
- type: 'null'
purpose:
type: string
rack_unit:
$ref: common.yaml#/definitions/positive_integer
ram_total:
type: integer
sas_hdd_num:
Expand Down Expand Up @@ -1034,7 +1034,7 @@ definitions:
required:
- id
- category
- component_id
- component
- hardware_product_id
- hint
- message
Expand All @@ -1048,7 +1048,7 @@ definitions:
- $ref: common.yaml#/definitions/uuid
category:
type: string
component_id:
component:
oneOf:
- type: 'null'
- type: string
Expand Down Expand Up @@ -1086,10 +1086,8 @@ definitions:
id:
$ref: common.yaml#/definitions/uuid
completed:
oneOf:
- type: 'null'
- type: string
format: date-time
type: string
format: date-time
created:
type: string
format: date-time
Expand Down Expand Up @@ -1122,10 +1120,8 @@ definitions:
id:
$ref: common.yaml#/definitions/uuid
completed:
oneOf:
- type: 'null'
- type: string
format: date-time
type: string
format: date-time
created:
type: string
format: date-time
Expand Down
2 changes: 1 addition & 1 deletion lib/Conch/Controller/DeviceReport.pm
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ sub process ($c) {
my $existing_device = $c->db_devices->active->find($c->stash('device_id'));

# capture information about the last report before we store the new one
# state can be: error, fail, processing, pass, where no validations on a valid report is
# state can be: error, fail, pass, where no validations on a valid report is
# considered to be a pass.
my ($previous_report_id, $previous_report_status);
if ($existing_device) {
Expand Down
5 changes: 2 additions & 3 deletions lib/Conch/Controller/Rack.pm
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,13 @@ sub get_assignment ($c) {
->search(undef, {
join => [
{ device_location => 'device' },
{ hardware_product => 'hardware_product_profile' },
'hardware_product',
],
'+columns' => {
device_id => 'device.id',
device_asset_tag => 'device.asset_tag',
hardware_product_name => 'hardware_product.name',
# TODO: this should be renamed in the db itself.
rack_unit_size => 'hardware_product_profile.rack_unit',
rack_unit_size => 'hardware_product.rack_unit_size',
},
collapse => 1,
})
Expand Down
20 changes: 5 additions & 15 deletions lib/Conch/Controller/RackLayout.pm
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ sub create ($c) {

my $new_rack_unit_size = $c->db_hardware_products
->search({ 'hardware_product.id' => $input->{hardware_product_id} })
->related_resultset('hardware_product_profile')
->get_column('rack_unit')->single;

return $c->status(409, { error => 'missing hardware product profile on hardware product id '.$input->{hardware_product_id} })
if not $new_rack_unit_size;
->get_column('rack_unit_size')->single;

if ($input->{rack_unit_start} + $new_rack_unit_size - 1 > $rack_size) {
$c->log->debug('layout ends at rack unit '.($input->{rack_unit_start} + $new_rack_unit_size - 1)
Expand Down Expand Up @@ -182,21 +178,15 @@ sub update ($c) {
# determine assigned slots, not counting the slots currently assigned to this layout (which
# we will be giving up)

my $current_rack_unit_size = $c->db_hardware_products->search(
{ 'hardware_product.id' => $layout->hardware_product_id })
->related_resultset('hardware_product_profile')->get_column('rack_unit')->single;

return $c->status(409, { error => 'missing hardware product profile on hardware product id '.$layout->hardware_product_id })
if not $current_rack_unit_size;
my $current_rack_unit_size = $c->db_hardware_products
->search({ 'hardware_product.id' => $layout->hardware_product_id })
->get_column('rack_unit_size')->single;

my $new_rack_unit_size = $input->{hardware_product_id}
? $c->db_hardware_products->search({ 'hardware_product.id' => $input->{hardware_product_id} })
->related_resultset('hardware_product_profile')->get_column('rack_unit')->single
->get_column('rack_unit_size')->single
: $current_rack_unit_size;

return $c->status(409, { error => 'missing hardware product profile on hardware product id '.$input->{hardware_product_id} })
if not $new_rack_unit_size;

my $new_rack_unit_start = $input->{rack_unit_start} // $layout->rack_unit_start;

if ($new_rack_unit_start + $new_rack_unit_size - 1 > $rack_size) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Conch/Controller/WorkspaceRack.pm
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ sub get_layout ($c) {
'layout.rack_unit_start' => 'rack_layouts.rack_unit_start',
(map +('layout.'.$_ => 'hardware_product.'.$_), qw(alias id name)),
'layout.vendor' => 'hardware_vendor.name',
'layout.rack_unit_size' => 'hardware_product_profile.rack_unit',
'layout.rack_unit_size' => 'hardware_product.rack_unit_size',
(map +('layout.device.'.$_ => 'device.'.$_), $c->schema->source('device')->columns),
},
join => [
'rack_role',
'datacenter_room',
{ rack_layouts => [
{ device_location => 'device' },
{ hardware_product => [ 'hardware_vendor', 'hardware_product_profile' ] },
{ hardware_product => 'hardware_vendor' },
] },
],
order_by => 'rack_layouts.rack_unit_start',
Expand Down
Loading

0 comments on commit 05b0357

Please sign in to comment.