Skip to content

api,server: fix VM.CREATE events on vm deploy without start#7421

Merged
yadvr merged 2 commits intoapache:4.18from
shapeblue:fix-vm-create-nostart-event
May 11, 2023
Merged

api,server: fix VM.CREATE events on vm deploy without start#7421
yadvr merged 2 commits intoapache:4.18from
shapeblue:fix-vm-create-nostart-event

Conversation

@shwstppr
Copy link
Copy Markdown
Contributor

@shwstppr shwstppr commented Apr 10, 2023

Description

Fixes #6697

Allows the server to generate started and completed events for VM.CREATE event type when VM is deployed with startvm=false.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

test-no-start.mp4

How Has This Been Tested?

Without fix (tested deplovm with and without start. VM.CREATE is not published as completed when startvm=false):

(local) 🦇 > deploy virtualmachine zoneid=104ca6f0-0a0f-4be7-ab4d-2ce1e091bb54 templateid=9f4b9f63-ed72-11ed-a4b9-645d8651f45a serviceofferingid=fca539e1-5b51-4b2f-a162-19a0594ca1fc name=no-fix-start
{
  "virtualmachine": {
    "account": "admin",
    "affinitygroup": [],
    "bootmode": "legacy",
    "boottype": "Bios",
    "cpunumber": 1,
    "cpuspeed": 500,
    "created": "2023-05-08T13:26:12+0530",
    "details": {},
    "displayname": "no-fix-start",
    "displayvm": true,
    "domain": "ROOT",
    "domainid": "2b10df2a-ed72-11ed-a4b9-645d8651f45a",
    "guestosid": "2aff87a2-ed72-11ed-a4b9-645d8651f45a",
    "haenable": false,
    "hasannotations": false,
    "hostcontrolstate": "Enabled",
    "hostid": "39d90d82-d64c-4691-bb11-8974475fedeb",
    "hostname": "SimulatedAgent.6642a6a9-2fb8-4d12-92cf-0237c21089aa",
    "hypervisor": "Simulator",
    "id": "915064ca-d5a6-493f-a4c8-f06ab0c606d8",
    "instancename": "i-2-3-VM",
    "isdynamicallyscalable": false,
    "jobid": "4c234e63-d735-41ad-aeda-ce5f5300d8f2",
    "jobstatus": 0,
    "lastupdated": "2023-05-08T13:26:15+0530",
    "memory": 512,
    "name": "no-fix-start",
    "nic": [
      {
        "broadcasturi": "vlan://123",
        "deviceid": "0",
        "extradhcpoption": [],
        "gateway": "10.1.1.1",
        "id": "3fcf85d8-78a9-47ab-90d3-147b5a8f84a8",
        "ipaddress": "10.1.1.128",
        "isdefault": true,
        "isolationuri": "vlan://123",
        "macaddress": "02:00:2e:35:00:01",
        "netmask": "255.255.255.0",
        "networkid": "0515986f-28cd-4a31-9eec-63535f7166d7",
        "networkname": "admin-network",
        "secondaryip": [],
        "traffictype": "Guest",
        "type": "Isolated"
      }
    ],
    "osdisplayname": "CentOS 5.6 (64-bit)",
    "ostypeid": "2aff87a2-ed72-11ed-a4b9-645d8651f45a",
    "passwordenabled": false,
    "pooltype": "NetworkFilesystem",
    "receivedbytes": 0,
    "rootdeviceid": 0,
    "rootdevicetype": "ROOT",
    "securitygroup": [],
    "sentbytes": 0,
    "serviceofferingid": "fca539e1-5b51-4b2f-a162-19a0594ca1fc",
    "serviceofferingname": "Small Instance",
    "state": "Running",
    "tags": [],
    "templatedisplaytext": "CentOS 5.6 (64-bit) no GUI (Simulator)",
    "templateid": "9f4b9f63-ed72-11ed-a4b9-645d8651f45a",
    "templatename": "CentOS 5.6 (64-bit) no GUI (Simulator)",
    "userid": "2b11cbb8-ed72-11ed-a4b9-645d8651f45a",
    "username": "admin",
    "zoneid": "104ca6f0-0a0f-4be7-ab4d-2ce1e091bb54",
    "zonename": "Sandbox-simulator"
  }
}
(local) 🐣 > list events filter=id,type,description,state pagesize=10 page=1
{
  "count": 8,
  "event": [
    {
      "description": "Successfully completed starting Vm. Vm Id: 915064ca-d5a6-493f-a4c8-f06ab0c606d8",
      "id": "cd9c2bc8-cc28-417f-8dea-7e3ee6e46914",
      "state": "Completed",
      "type": "VM.CREATE"
    },
    {
      "description": "Assigned Zone Vlan: 123 Network Id: 204",
      "id": "384bbe1d-4c80-4516-b1c7-7e15abf6bfae",
      "state": "Completed",
      "type": "ZONE.VLAN.ASSIGN"
    },
    {
      "description": "Successfully created entity for creating firewall rule",
      "id": "081c70cb-50fb-4a98-978a-efbc0414293e",
      "state": "Created",
      "type": "FIREWALL.OPEN"
    },
    {
      "description": "Successfully created entity for creating ROOT volume. Volume Id: 275df8d6-ddbe-4baa-868a-a659a58c3714 Vm Id: 84322306-0090-4267-9067-7f5636d01cd0",
      "id": "91fcad75-f3b6-434a-85e1-5515ed6a0e67",
      "state": "Created",
      "type": "VOLUME.CREATE"
    },
    {
      "description": "Successfully created entity for creating ROOT volume. Volume Id: 1d30c846-54f5-4ed9-a920-9693c79e8565 Vm Id: 915064ca-d5a6-493f-a4c8-f06ab0c606d8",
      "id": "a2c86302-8036-479c-998b-5282e806c709",
      "state": "Created",
      "type": "VOLUME.CREATE"
    },
    {
      "description": "starting Vm. Vm Id: 915064ca-d5a6-493f-a4c8-f06ab0c606d8",
      "id": "8c5de74b-58ae-473c-9ce3-0231b5a5964c",
      "state": "Scheduled",
      "type": "VM.CREATE"
    },
    {
      "description": "starting Vm. Vm Id: 915064ca-d5a6-493f-a4c8-f06ab0c606d8",
      "id": "a1675755-dc7c-4791-9454-2d257af3749f",
      "state": "Started",
      "type": "VM.CREATE"
    },
    {
      "description": "user has logged in from IP Address /127.0.0.1",
      "id": "83278bb1-7f7d-4543-a035-baebc997fe7a",
      "state": "Completed",
      "type": "USER.LOGIN"
    }
  ]
}
(local) 🕷 > deploy virtualmachine zoneid=104ca6f0-0a0f-4be7-ab4d-2ce1e091bb54 templateid=9f4b9f63-ed72-11ed-a4b9-645d8651f45a serviceofferingid=fca539e1-5b51-4b2f-a162-19a0594ca1fc startvm=false name=no-fix-no-start
{
  "virtualmachine": {
    "account": "admin",
    "affinitygroup": [],
    "cpunumber": 1,
    "cpuspeed": 500,
    "created": "2023-05-08T13:27:48+0530",
    "details": {
      "deployvm": "true"
    },
    "displayname": "no-fix-no-start",
    "displayvm": true,
    "domain": "ROOT",
    "domainid": "2b10df2a-ed72-11ed-a4b9-645d8651f45a",
    "guestosid": "2aff87a2-ed72-11ed-a4b9-645d8651f45a",
    "haenable": false,
    "hasannotations": false,
    "hypervisor": "Simulator",
    "id": "e4f30c4a-d9cd-4f46-a86e-eb702533c662",
    "instancename": "i-2-5-VM",
    "isdynamicallyscalable": false,
    "jobid": "f0492d42-20de-4ba3-9289-c374c574c1e7",
    "jobstatus": 0,
    "memory": 512,
    "name": "no-fix-no-start",
    "nic": [
      {
        "broadcasturi": "vlan://123",
        "deviceid": "0",
        "extradhcpoption": [],
        "gateway": "10.1.1.1",
        "id": "37783efa-8acf-453f-bc97-ba50714907b7",
        "ipaddress": "10.1.1.113",
        "isdefault": true,
        "isolationuri": "vlan://123",
        "macaddress": "02:00:31:5b:00:03",
        "netmask": "255.255.255.0",
        "networkid": "0515986f-28cd-4a31-9eec-63535f7166d7",
        "networkname": "admin-network",
        "secondaryip": [],
        "traffictype": "Guest",
        "type": "Isolated"
      }
    ],
    "osdisplayname": "CentOS 5.6 (64-bit)",
    "ostypeid": "2aff87a2-ed72-11ed-a4b9-645d8651f45a",
    "passwordenabled": false,
    "receivedbytes": 0,
    "rootdeviceid": 0,
    "rootdevicetype": "ROOT",
    "securitygroup": [],
    "sentbytes": 0,
    "serviceofferingid": "fca539e1-5b51-4b2f-a162-19a0594ca1fc",
    "serviceofferingname": "Small Instance",
    "state": "Stopped",
    "tags": [],
    "templatedisplaytext": "CentOS 5.6 (64-bit) no GUI (Simulator)",
    "templateid": "9f4b9f63-ed72-11ed-a4b9-645d8651f45a",
    "templatename": "CentOS 5.6 (64-bit) no GUI (Simulator)",
    "userid": "2b11cbb8-ed72-11ed-a4b9-645d8651f45a",
    "username": "admin",
    "zoneid": "104ca6f0-0a0f-4be7-ab4d-2ce1e091bb54",
    "zonename": "Sandbox-simulator"
  }
}
(local) 🦍 > list events filter=id,type,description,state pagesize=6 page=1
{
  "count": 10,
  "event": [
    {
      "description": "Successfully created entity for creating ROOT volume. Volume Id: 71bd070e-b2e3-4543-b23a-6052efc64dd2 Vm Id: e4f30c4a-d9cd-4f46-a86e-eb702533c662",
      "id": "f472d5ed-3a6f-4ebf-9123-f303b2fc216b",
      "state": "Created",
      "type": "VOLUME.CREATE"
    },
    {
      "description": "starting Vm. Vm Id: e4f30c4a-d9cd-4f46-a86e-eb702533c662",
      "id": "c509137b-f3c9-4629-bea9-abca852a50e8",
      "state": "Scheduled",
      "type": "VM.CREATE"
    },
    {
      "description": "Successfully completed starting Vm. Vm Id: 915064ca-d5a6-493f-a4c8-f06ab0c606d8",
      "id": "cd9c2bc8-cc28-417f-8dea-7e3ee6e46914",
      "state": "Completed",
      "type": "VM.CREATE"
    },
    {
      "description": "Assigned Zone Vlan: 123 Network Id: 204",
      "id": "384bbe1d-4c80-4516-b1c7-7e15abf6bfae",
      "state": "Completed",
      "type": "ZONE.VLAN.ASSIGN"
    },
    {
      "description": "Successfully created entity for creating firewall rule",
      "id": "081c70cb-50fb-4a98-978a-efbc0414293e",
      "state": "Created",
      "type": "FIREWALL.OPEN"
    },
    {
      "description": "Successfully created entity for creating ROOT volume. Volume Id: 275df8d6-ddbe-4baa-868a-a659a58c3714 Vm Id: 84322306-0090-4267-9067-7f5636d01cd0",
      "id": "91fcad75-f3b6-434a-85e1-5515ed6a0e67",
      "state": "Created",
      "type": "VOLUME.CREATE"
    }
  ]
}

With fix (VM.CREATE as completed is published even with startvm=false)

(local) 🐣 > deploy virtualmachine zoneid=104ca6f0-0a0f-4be7-ab4d-2ce1e091bb54 templateid=9f4b9f63-ed72-11ed-a4b9-645d8651f45a serviceofferingid=fca539e1-5b51-4b2f-a162-19a0594ca1fc name=fix-start
{
  "virtualmachine": {
    "account": "admin",
    "affinitygroup": [],
    "bootmode": "legacy",
    "boottype": "Bios",
    "cpunumber": 1,
    "cpuspeed": 500,
    "created": "2023-05-08T13:47:49+0530",
    "details": {},
    "displayname": "fix-start",
    "displayvm": true,
    "domain": "ROOT",
    "domainid": "2b10df2a-ed72-11ed-a4b9-645d8651f45a",
    "guestosid": "2aff87a2-ed72-11ed-a4b9-645d8651f45a",
    "haenable": false,
    "hasannotations": false,
    "hostcontrolstate": "Enabled",
    "hostid": "ae82f829-5fba-49b5-8c77-645f48c64918",
    "hostname": "SimulatedAgent.2bc85dd9-7015-485a-8225-569c4058ac6d",
    "hypervisor": "Simulator",
    "id": "5d8dd74a-efc3-414b-9966-61553223a73a",
    "instancename": "i-2-6-QA",
    "isdynamicallyscalable": false,
    "jobid": "388f779f-9cdf-448c-b98e-b87c41f56566",
    "jobstatus": 0,
    "lastupdated": "2023-05-08T13:47:51+0530",
    "memory": 512,
    "name": "fix-start",
    "nic": [
      {
        "broadcasturi": "vlan://123",
        "deviceid": "0",
        "extradhcpoption": [],
        "gateway": "10.1.1.1",
        "id": "3a4c5f63-2d6d-4d35-b183-1416deb26f42",
        "ipaddress": "10.1.1.170",
        "isdefault": true,
        "isolationuri": "vlan://123",
        "macaddress": "02:00:59:1e:00:04",
        "netmask": "255.255.255.0",
        "networkid": "0515986f-28cd-4a31-9eec-63535f7166d7",
        "networkname": "admin-network",
        "secondaryip": [],
        "traffictype": "Guest",
        "type": "Isolated"
      }
    ],
    "osdisplayname": "CentOS 5.6 (64-bit)",
    "ostypeid": "2aff87a2-ed72-11ed-a4b9-645d8651f45a",
    "passwordenabled": false,
    "pooltype": "NetworkFilesystem",
    "receivedbytes": 0,
    "rootdeviceid": 0,
    "rootdevicetype": "ROOT",
    "securitygroup": [],
    "sentbytes": 0,
    "serviceofferingid": "fca539e1-5b51-4b2f-a162-19a0594ca1fc",
    "serviceofferingname": "Small Instance",
    "state": "Running",
    "tags": [],
    "templatedisplaytext": "CentOS 5.6 (64-bit) no GUI (Simulator)",
    "templateid": "9f4b9f63-ed72-11ed-a4b9-645d8651f45a",
    "templatename": "CentOS 5.6 (64-bit) no GUI (Simulator)",
    "userid": "2b11cbb8-ed72-11ed-a4b9-645d8651f45a",
    "username": "admin",
    "zoneid": "104ca6f0-0a0f-4be7-ab4d-2ce1e091bb54",
    "zonename": "Sandbox-simulator"
  }
}
(local) 🐓 > list events filter=id,type,description,state pagesize=8 page=1
{
  "count": 15,
  "event": [
    {
      "description": "Successfully completed deploying Vm. Vm Id: 5d8dd74a-efc3-414b-9966-61553223a73a",
      "id": "e55c9bf2-ad3d-49b7-9acc-1eecb25e370a",
      "state": "Completed",
      "type": "VM.CREATE"
    },
    {
      "description": "user has logged in from IP Address /127.0.0.1",
      "id": "2e1dfa11-3780-47b9-b86b-21f1b3d471b0",
      "state": "Completed",
      "type": "USER.LOGIN"
    },
    {
      "description": "Successfully created entity for creating ROOT volume. Volume Id: e4dd0164-de81-41e7-b64e-5d84d46614b7 Vm Id: 5d8dd74a-efc3-414b-9966-61553223a73a",
      "id": "02df99c3-e7f3-402d-8d2d-56d1f117ecc5",
      "state": "Created",
      "type": "VOLUME.CREATE"
    },
    {
      "description": "starting Vm. Vm Id: 5d8dd74a-efc3-414b-9966-61553223a73a",
      "id": "bb09ddf4-e266-437a-8bc1-61cbde7094d2",
      "state": "Scheduled",
      "type": "VM.CREATE"
    },
    {
      "description": "deploying Vm. Vm Id: 5d8dd74a-efc3-414b-9966-61553223a73a",
      "id": "9ae51b12-22cc-4dd9-8b40-0b499a7df897",
      "state": "Started",
      "type": "VM.CREATE"
    },
    {
      "description": "Successfully created entity for creating ROOT volume. Volume Id: 71bd070e-b2e3-4543-b23a-6052efc64dd2 Vm Id: e4f30c4a-d9cd-4f46-a86e-eb702533c662",
      "id": "f472d5ed-3a6f-4ebf-9123-f303b2fc216b",
      "state": "Created",
      "type": "VOLUME.CREATE"
    },
    {
      "description": "starting Vm. Vm Id: e4f30c4a-d9cd-4f46-a86e-eb702533c662",
      "id": "c509137b-f3c9-4629-bea9-abca852a50e8",
      "state": "Scheduled",
      "type": "VM.CREATE"
    },
    {
      "description": "Successfully completed starting Vm. Vm Id: 915064ca-d5a6-493f-a4c8-f06ab0c606d8",
      "id": "cd9c2bc8-cc28-417f-8dea-7e3ee6e46914",
      "state": "Completed",
      "type": "VM.CREATE"
    }
  ]
}
(local) 🐓 > deploy virtualmachine zoneid=104ca6f0-0a0f-4be7-ab4d-2ce1e091bb54 templateid=9f4b9f63-ed72-11ed-a4b9-645d8651f45a serviceofferingid=fca539e1-5b51-4b2f-a162-19a0594ca1fc startvm=false name=fix-no-start
{
  "virtualmachine": {
    "account": "admin",
    "affinitygroup": [],
    "cpunumber": 1,
    "cpuspeed": 500,
    "created": "2023-05-08T13:48:34+0530",
    "details": {
      "deployvm": "true"
    },
    "displayname": "fix-no-start",
    "displayvm": true,
    "domain": "ROOT",
    "domainid": "2b10df2a-ed72-11ed-a4b9-645d8651f45a",
    "guestosid": "2aff87a2-ed72-11ed-a4b9-645d8651f45a",
    "haenable": false,
    "hasannotations": false,
    "hypervisor": "Simulator",
    "id": "0434ffb3-2006-4e93-8c25-089803851377",
    "instancename": "i-2-7-QA",
    "isdynamicallyscalable": false,
    "jobid": "2b0c517a-f60f-4051-a0fa-7e27378ae804",
    "jobstatus": 0,
    "memory": 512,
    "name": "fix-no-start",
    "nic": [
      {
        "broadcasturi": "vlan://123",
        "deviceid": "0",
        "extradhcpoption": [],
        "gateway": "10.1.1.1",
        "id": "30541ce3-4559-4975-b17c-a998a3aba88a",
        "ipaddress": "10.1.1.250",
        "isdefault": true,
        "isolationuri": "vlan://123",
        "macaddress": "02:00:05:dd:00:05",
        "netmask": "255.255.255.0",
        "networkid": "0515986f-28cd-4a31-9eec-63535f7166d7",
        "networkname": "admin-network",
        "secondaryip": [],
        "traffictype": "Guest",
        "type": "Isolated"
      }
    ],
    "osdisplayname": "CentOS 5.6 (64-bit)",
    "ostypeid": "2aff87a2-ed72-11ed-a4b9-645d8651f45a",
    "passwordenabled": false,
    "receivedbytes": 0,
    "rootdeviceid": 0,
    "rootdevicetype": "ROOT",
    "securitygroup": [],
    "sentbytes": 0,
    "serviceofferingid": "fca539e1-5b51-4b2f-a162-19a0594ca1fc",
    "serviceofferingname": "Small Instance",
    "state": "Stopped",
    "tags": [],
    "templatedisplaytext": "CentOS 5.6 (64-bit) no GUI (Simulator)",
    "templateid": "9f4b9f63-ed72-11ed-a4b9-645d8651f45a",
    "templatename": "CentOS 5.6 (64-bit) no GUI (Simulator)",
    "userid": "2b11cbb8-ed72-11ed-a4b9-645d8651f45a",
    "username": "admin",
    "zoneid": "104ca6f0-0a0f-4be7-ab4d-2ce1e091bb54",
    "zonename": "Sandbox-simulator"
  }
}
(local) 🐛 > list events filter=id,type,description,state pagesize=8 page=1
{
  "count": 19,
  "event": [
    {
      "description": "Successfully completed deploying Vm. Vm Id: 0434ffb3-2006-4e93-8c25-089803851377",
      "id": "e5d8cb91-2f11-47d0-9fb2-4786a6d5a4db",
      "state": "Completed",
      "type": "VM.CREATE"
    },
    {
      "description": "deploying Vm. Vm Id: 0434ffb3-2006-4e93-8c25-089803851377",
      "id": "bfd1709e-da75-498f-9ada-657df6fb5859",
      "state": "Started",
      "type": "VM.CREATE"
    },
    {
      "description": "starting Vm. Vm Id: 0434ffb3-2006-4e93-8c25-089803851377",
      "id": "da819f7d-b69a-4666-a772-a2115a4c0440",
      "state": "Scheduled",
      "type": "VM.CREATE"
    },
    {
      "description": "Successfully created entity for creating ROOT volume. Volume Id: 9bdfa54b-bd51-4c43-b0d2-612be1af9bc6 Vm Id: 0434ffb3-2006-4e93-8c25-089803851377",
      "id": "0967ccd2-2571-4ce2-89ab-a8f2caf4ce1c",
      "state": "Created",
      "type": "VOLUME.CREATE"
    },
    {
      "description": "Successfully completed deploying Vm. Vm Id: 5d8dd74a-efc3-414b-9966-61553223a73a",
      "id": "e55c9bf2-ad3d-49b7-9acc-1eecb25e370a",
      "state": "Completed",
      "type": "VM.CREATE"
    },
    {
      "description": "starting Vm. Vm Id: 5d8dd74a-efc3-414b-9966-61553223a73a",
      "id": "bb09ddf4-e266-437a-8bc1-61cbde7094d2",
      "state": "Scheduled",
      "type": "VM.CREATE"
    },
    {
      "description": "user has logged in from IP Address /127.0.0.1",
      "id": "2e1dfa11-3780-47b9-b86b-21f1b3d471b0",
      "state": "Completed",
      "type": "USER.LOGIN"
    },
    {
      "description": "Successfully created entity for creating ROOT volume. Volume Id: e4dd0164-de81-41e7-b64e-5d84d46614b7 Vm Id: 5d8dd74a-efc3-414b-9966-61553223a73a",
      "id": "02df99c3-e7f3-402d-8d2d-56d1f117ecc5",
      "state": "Created",
      "type": "VOLUME.CREATE"
    }
  ]
}

Fixes apache#6697

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 10, 2023

Codecov Report

Merging #7421 (a5ebe20) into 4.18 (9e13042) will decrease coverage by 0.01%.
The diff coverage is 0.00%.

@@             Coverage Diff              @@
##               4.18    #7421      +/-   ##
============================================
- Coverage     12.69%   12.69%   -0.01%     
+ Complexity     8661     8656       -5     
============================================
  Files          2717     2717              
  Lines        256165   256163       -2     
  Branches      39928    39927       -1     
============================================
- Hits          32526    32512      -14     
- Misses       219504   219517      +13     
+ Partials       4135     4134       -1     
Impacted Files Coverage Δ
.../src/main/java/com/cloud/vm/UserVmManagerImpl.java 7.34% <0.00%> (-0.01%) ⬇️

... and 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@sonarqubecloud
Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@shwstppr
Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@shwstppr a Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@shwstppr shwstppr marked this pull request as ready for review April 11, 2023 06:58
@blueorangutan
Copy link
Copy Markdown

Packaging result: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 5895

Copy link
Copy Markdown
Member

@yadvr yadvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, didn't test it though

@yadvr yadvr added this to the 4.18.1.0 milestone Apr 13, 2023

@Override
@ActionEvent(eventType = EventTypes.EVENT_VM_CREATE, eventDescription = "starting Vm", async = true)
@ActionEvent(eventType = EventTypes.EVENT_VM_CREATE, eventDescription = "deploying Vm", async = true)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shwstppr , it seems to me this should not yield an event for EVENT_VM_CREATE but for EVENT_VM_START. The EVENT_VM_CREATEshould already have been yielded on_userVmService.createVirtualMachine(this)`.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaanHoogland As of now, when deploying a new VM, CloudStack doesn't publishes an EVENT_VM_START event and EVENT_VM_CREATE is not published during _userVmService.createVirtualMachine(this).
I feel this is apt behaviour because _userVmService.createVirtualMachine(this) will just create a DB record and actual deployment could fail in many scenarios.
Also, for a BaseAsyncCmd event with Scheduled state is published only when execute method of the API command class is executed, https://github.com/apache/cloudstack/blob/main/server/src/main/java/com/cloud/api/ApiServer.java#L732-L734. Therefore, even if we refactor EVENT_VM_CREATE publishing on userVmService.createVirtualMachine and EVENT_VM_START on userVmService.startVirtualMachine, without major refactor ApiServer order of events would look like,

EVENT_VM_CREATE Started
EVENT_VM_CREATE Completed
EVENT_VM_CREATE Scheduled
EVENT_VM_STARTED Started
EVENT_VM_STARTED Completed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That first point you make makes sense, but what is the order of events now?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the 'deploy' would make sense for both newly deployed and started.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaanHoogland updated PR desc with tests cc @rohityadavcloud

@yadvr
Copy link
Copy Markdown
Member

yadvr commented Apr 20, 2023

Should we do a VM.DEPLOY? (deploy could mean both start or create)

@yadvr yadvr requested a review from DaanHoogland May 8, 2023 11:49
Copy link
Copy Markdown
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, though I think we may have to revisit what event are generated when at some later point (usage refactor)

@shwstppr
Copy link
Copy Markdown
Contributor Author

Should we do a VM.DEPLOY? (deploy could mean both start or create)

@rohityadavcloud will it introduce any issues with usage or existing integrations while consuming events? Maybe it can be discussed/changed in a major release or as part of usage refactor

@yadvr
Copy link
Copy Markdown
Member

yadvr commented May 11, 2023

If the event is still EventTypes.EVENT_VM_CREATE and we're only changing the description, I don't think so @shwstppr but perhaps we should test?

@shwstppr
Copy link
Copy Markdown
Contributor Author

@rohityadavcloud Sorry didn't get you completely.
This PR or a change in the event description won't create an issue but if we refactor the event type to VM.DEPLOY as you said in your last comment I feel there could be an issue with usage processing as usage_event stores the type of the event,

MariaDB [cloud_usage]> select * from usage_event WHERE type='VM.CREATE';
+----+-----------+------------+---------------------+---------+-------------+-----------------------------+-------------+-------------+------+---------------+-----------+--------------+
| id | type      | account_id | created             | zone_id | resource_id | resource_name               | offering_id | template_id | size | resource_type | processed | virtual_size |
+----+-----------+------------+---------------------+---------+-------------+-----------------------------+-------------+-------------+------+---------------+-----------+--------------+
|  6 | VM.CREATE |          2 | 2023-05-10 12:24:53 |       1 |           4 | test-control-188059f1a44    |          13 |           8 | NULL | VMware        |         1 |         NULL |
| 10 | VM.CREATE |          2 | 2023-05-10 12:25:19 |       1 |           5 | test-node-188059f80a5       |          13 |           8 | NULL | VMware        |         1 |         NULL |
| 26 | VM.CREATE |          2 | 2023-05-10 13:02:41 |       1 |           6 | test-control-18805c0e74b    |          13 |           8 | NULL | VMware        |         1 |         NULL |
| 30 | VM.CREATE |          2 | 2023-05-10 13:04:38 |       1 |           7 | test-node-18805c3790b       |          13 |           8 | NULL | VMware        |         1 |         NULL |
| 44 | VM.CREATE |          2 | 2023-05-10 13:09:59 |       1 |           8 | ftret-control-18805c86337   |          13 |           8 | NULL | VMware        |         1 |         NULL |
| 48 | VM.CREATE |          2 | 2023-05-10 13:10:19 |       1 |           9 | ftret-node-18805c8b35e      |          13 |           8 | NULL | VMware        |         1 |         NULL |
| 65 | VM.CREATE |          2 | 2023-05-10 13:35:39 |       1 |          10 | vdsgfds-control-18805dfe3ba |          13 |           8 | NULL | VMware        |         1 |         NULL |
| 69 | VM.CREATE |          2 | 2023-05-10 13:36:17 |       1 |          11 | vdsgfds-node-18805e079db    |          13 |           8 | NULL | VMware        |         1 |         NULL |
+----+-----------+------------+---------------------+---------+-------------+-----------------------------+-------------+-------------+------+---------------+-----------+--------------+
8 rows in set (0.00 sec)

Also, the same event type would be published on the event bus

@yadvr
Copy link
Copy Markdown
Member

yadvr commented May 11, 2023

@shwstppr my bad, no I didn't mean the event type but only the description.

@yadvr yadvr merged commit a0eb0aa into apache:4.18 May 11, 2023
@yadvr yadvr deleted the fix-vm-create-nostart-event branch May 11, 2023 17:53
@yadvr
Copy link
Copy Markdown
Member

yadvr commented May 11, 2023

@shwstppr this seem to have broken the UI build, could you have a look tomorrow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants