Skip to content

Commit b240f80

Browse files
author
GutoVeronezi
committed
Always retrieve the hypervisor type from the VM
1 parent 67af06e commit b240f80

File tree

5 files changed

+217
-19
lines changed

5 files changed

+217
-19
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.upgrade.dao;
18+
19+
import com.cloud.upgrade.SystemVmTemplateRegistration;
20+
import com.cloud.utils.exception.CloudRuntimeException;
21+
import org.apache.log4j.Logger;
22+
23+
import java.io.InputStream;
24+
import java.sql.Connection;
25+
26+
public class Upgrade41700to41710 implements DbUpgrade, DbUpgradeSystemVmTemplate {
27+
28+
final static Logger LOG = Logger.getLogger(Upgrade41610to41700.class);
29+
private SystemVmTemplateRegistration systemVmTemplateRegistration;
30+
31+
@Override
32+
public String[] getUpgradableVersionRange() {
33+
return new String[] {"4.17.0.0", "4.17.1.0"};
34+
}
35+
36+
@Override
37+
public String getUpgradedVersion() {
38+
return "4.17.1.0";
39+
}
40+
41+
@Override
42+
public boolean supportsRollingUpgrade() {
43+
return false;
44+
}
45+
46+
@Override
47+
public InputStream[] getPrepareScripts() {
48+
final String scriptFile = "META-INF/db/schema-41700to41710.sql";
49+
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
50+
if (script == null) {
51+
throw new CloudRuntimeException("Unable to find " + scriptFile);
52+
}
53+
54+
return new InputStream[] {script};
55+
}
56+
57+
@Override
58+
public void performDataMigration(Connection conn) {
59+
60+
}
61+
62+
@Override
63+
public InputStream[] getCleanupScripts() {
64+
final String scriptFile = "META-INF/db/schema-41610to41700-cleanup.sql";
65+
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
66+
if (script == null) {
67+
throw new CloudRuntimeException("Unable to find " + scriptFile);
68+
}
69+
70+
return new InputStream[] {script};
71+
}
72+
73+
private void initSystemVmTemplateRegistration() {
74+
systemVmTemplateRegistration = new SystemVmTemplateRegistration("");
75+
}
76+
77+
@Override
78+
public void updateSystemVmTemplates(Connection conn) {
79+
LOG.debug("Updating System Vm template IDs");
80+
initSystemVmTemplateRegistration();
81+
try {
82+
systemVmTemplateRegistration.updateSystemVmTemplates(conn);
83+
} catch (Exception e) {
84+
throw new CloudRuntimeException("Failed to find / register SystemVM template(s)");
85+
}
86+
}
87+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
--;
19+
-- Schema upgrade from 4.17.0.0 to 4.17.1.0
20+
--;
21+
22+
23+
-- Retrieve the hypervisor_type from vm_instance
24+
DROP VIEW IF EXISTS `cloud`.`domain_router_view`;
25+
CREATE VIEW `cloud`.`domain_router_view` AS
26+
select
27+
vm_instance.id id,
28+
vm_instance.name name,
29+
account.id account_id,
30+
account.uuid account_uuid,
31+
account.account_name account_name,
32+
account.type account_type,
33+
domain.id domain_id,
34+
domain.uuid domain_uuid,
35+
domain.name domain_name,
36+
domain.path domain_path,
37+
projects.id project_id,
38+
projects.uuid project_uuid,
39+
projects.name project_name,
40+
vm_instance.uuid uuid,
41+
vm_instance.created created,
42+
vm_instance.state state,
43+
vm_instance.removed removed,
44+
vm_instance.pod_id pod_id,
45+
vm_instance.instance_name instance_name,
46+
vm_instance.hypervisor_type,
47+
host_pod_ref.uuid pod_uuid,
48+
data_center.id data_center_id,
49+
data_center.uuid data_center_uuid,
50+
data_center.name data_center_name,
51+
data_center.networktype data_center_type,
52+
data_center.dns1 dns1,
53+
data_center.dns2 dns2,
54+
data_center.ip6_dns1 ip6_dns1,
55+
data_center.ip6_dns2 ip6_dns2,
56+
host.id host_id,
57+
host.uuid host_uuid,
58+
host.name host_name,
59+
host.cluster_id cluster_id,
60+
vm_template.id template_id,
61+
vm_template.uuid template_uuid,
62+
service_offering.id service_offering_id,
63+
disk_offering.uuid service_offering_uuid,
64+
disk_offering.name service_offering_name,
65+
nics.id nic_id,
66+
nics.uuid nic_uuid,
67+
nics.network_id network_id,
68+
nics.ip4_address ip_address,
69+
nics.ip6_address ip6_address,
70+
nics.ip6_gateway ip6_gateway,
71+
nics.ip6_cidr ip6_cidr,
72+
nics.default_nic is_default_nic,
73+
nics.gateway gateway,
74+
nics.netmask netmask,
75+
nics.mac_address mac_address,
76+
nics.broadcast_uri broadcast_uri,
77+
nics.isolation_uri isolation_uri,
78+
vpc.id vpc_id,
79+
vpc.uuid vpc_uuid,
80+
vpc.name vpc_name,
81+
networks.uuid network_uuid,
82+
networks.name network_name,
83+
networks.network_domain network_domain,
84+
networks.traffic_type traffic_type,
85+
networks.guest_type guest_type,
86+
async_job.id job_id,
87+
async_job.uuid job_uuid,
88+
async_job.job_status job_status,
89+
async_job.account_id job_account_id,
90+
domain_router.template_version template_version,
91+
domain_router.scripts_version scripts_version,
92+
domain_router.is_redundant_router is_redundant_router,
93+
domain_router.redundant_state redundant_state,
94+
domain_router.stop_pending stop_pending,
95+
domain_router.role role
96+
from
97+
`cloud`.`domain_router`
98+
inner join
99+
`cloud`.`vm_instance` ON vm_instance.id = domain_router.id
100+
inner join
101+
`cloud`.`account` ON vm_instance.account_id = account.id
102+
inner join
103+
`cloud`.`domain` ON vm_instance.domain_id = domain.id
104+
left join
105+
`cloud`.`host_pod_ref` ON vm_instance.pod_id = host_pod_ref.id
106+
left join
107+
`cloud`.`projects` ON projects.project_account_id = account.id
108+
left join
109+
`cloud`.`data_center` ON vm_instance.data_center_id = data_center.id
110+
left join
111+
`cloud`.`host` ON vm_instance.host_id = host.id
112+
left join
113+
`cloud`.`vm_template` ON vm_instance.vm_template_id = vm_template.id
114+
left join
115+
`cloud`.`service_offering` ON vm_instance.service_offering_id = service_offering.id
116+
left join
117+
`cloud`.`disk_offering` ON vm_instance.service_offering_id = disk_offering.id
118+
left join
119+
`cloud`.`nics` ON vm_instance.id = nics.instance_id and nics.removed is null
120+
left join
121+
`cloud`.`networks` ON nics.network_id = networks.id
122+
left join
123+
`cloud`.`vpc` ON domain_router.vpc_id = vpc.id and vpc.removed is null
124+
left join
125+
`cloud`.`async_job` ON async_job.instance_id = vm_instance.id
126+
and async_job.instance_type = 'DomainRouter'
127+
and async_job.job_status = 0;

server/src/main/java/com/cloud/api/ApiDBUtils.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@
329329
import org.apache.cloudstack.resourcedetail.dao.DiskOfferingDetailsDao;
330330
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
331331
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
332-
import org.apache.commons.lang3.StringUtils;
333332

334333
import javax.annotation.PostConstruct;
335334
import javax.inject.Inject;
@@ -1795,17 +1794,7 @@ public static String findJobInstanceUuid(AsyncJob job) {
17951794
///////////////////////////////////////////////////////////////////////
17961795

17971796
public static DomainRouterResponse newDomainRouterResponse(DomainRouterJoinVO vr, Account caller) {
1798-
DomainRouterResponse response = s_domainRouterJoinDao.newDomainRouterResponse(vr, caller);
1799-
if (StringUtils.isBlank(response.getHypervisor())) {
1800-
VMInstanceVO vm = ApiDBUtils.findVMInstanceById(vr.getId());
1801-
if (vm.getLastHostId() != null) {
1802-
HostVO lastHost = ApiDBUtils.findHostById(vm.getLastHostId());
1803-
if (lastHost != null) {
1804-
response.setHypervisor(lastHost.getHypervisorType().toString());
1805-
}
1806-
}
1807-
}
1808-
return response;
1797+
return s_domainRouterJoinDao.newDomainRouterResponse(vr, caller);
18091798
}
18101799

18111800
public static DomainRouterResponse fillRouterDetails(DomainRouterResponse vrData, DomainRouterJoinVO vr) {

server/src/main/java/com/cloud/api/ApiResponseHelper.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,18 +1532,13 @@ public SystemVmResponse createSystemVmResponse(VirtualMachine vm) {
15321532
vmResponse.setTemplateName(template.getName());
15331533
}
15341534
vmResponse.setCreated(vm.getCreated());
1535+
vmResponse.setHypervisor(vm.getHypervisorType().toString());
15351536

15361537
if (vm.getHostId() != null) {
15371538
Host host = ApiDBUtils.findHostById(vm.getHostId());
15381539
if (host != null) {
15391540
vmResponse.setHostId(host.getUuid());
15401541
vmResponse.setHostName(host.getName());
1541-
vmResponse.setHypervisor(host.getHypervisorType().toString());
1542-
}
1543-
} else if (vm.getLastHostId() != null) {
1544-
Host lastHost = ApiDBUtils.findHostById(vm.getLastHostId());
1545-
if (lastHost != null) {
1546-
vmResponse.setHypervisor(lastHost.getHypervisorType().toString());
15471542
}
15481543
}
15491544

server/src/main/java/com/cloud/api/query/dao/DomainRouterJoinDaoImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public DomainRouterResponse newDomainRouterResponse(DomainRouterJoinVO router, A
118118
routerResponse.setRequiresUpgrade(true);
119119
}
120120

121+
routerResponse.setHypervisor(router.getHypervisorType().toString());
121122
routerResponse.setHasAnnotation(annotationDao.hasAnnotations(router.getUuid(), AnnotationService.EntityType.VR.name(),
122123
_accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())));
123124

@@ -126,7 +127,6 @@ public DomainRouterResponse newDomainRouterResponse(DomainRouterJoinVO router, A
126127
if (router.getHostId() != null) {
127128
routerResponse.setHostId(router.getHostUuid());
128129
routerResponse.setHostName(router.getHostName());
129-
routerResponse.setHypervisor(router.getHypervisorType().toString());
130130
}
131131
routerResponse.setPodId(router.getPodUuid());
132132
HostPodVO pod = ApiDBUtils.findPodById(router.getPodId());

0 commit comments

Comments
 (0)