Skip to content

Commit

Permalink
Move saveDetails method to UserVmDetailsDaoImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
BartJM committed Sep 23, 2024
1 parent 37ec820 commit 9d3550d
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ public interface ConsoleProxyDao extends GenericDao<ConsoleProxyVO, Long> {

public void update(long id, int activeSession, Date updateTime, byte[] sessionDetails);

public void saveDetails(ConsoleProxyVO vm);

public void saveDetails(ConsoleProxyVO vm, List<String> hiddenDetails);

public List<ConsoleProxyVO> getProxyListInStates(long dataCenterId, State... states);

public List<ConsoleProxyVO> getProxyListInStates(State... states);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;


import org.springframework.stereotype.Component;
Expand All @@ -37,9 +36,6 @@
import com.cloud.utils.db.UpdateBuilder;
import com.cloud.vm.ConsoleProxyVO;
import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.UserVmDetailVO;

import javax.inject.Inject;

@Component
public class ConsoleProxyDaoImpl extends GenericDaoBase<ConsoleProxyVO, Long> implements ConsoleProxyDao {
Expand Down Expand Up @@ -95,9 +91,6 @@ public class ConsoleProxyDaoImpl extends GenericDaoBase<ConsoleProxyVO, Long> im

protected final Attribute _updateTimeAttr;

@Inject
protected UserVmDetailsDao _detailsDao;

public ConsoleProxyDaoImpl() {
DataCenterStatusSearch = createSearchBuilder();
DataCenterStatusSearch.and("dc", DataCenterStatusSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
Expand Down Expand Up @@ -338,27 +331,4 @@ public List<ConsoleProxyVO> listByLastHostId(long hostId) {
sc.setParameters("state", State.Stopped);
return listBy(sc);
}

@Override
public void saveDetails(ConsoleProxyVO vm) {
saveDetails(vm, new ArrayList<String>());
}

@Override
public void saveDetails(ConsoleProxyVO vm, List<String> hiddenDetails) {
Map<String, String> detailsStr = vm.getDetails();
if (detailsStr == null) {
return;
}

final Map<String, Boolean> visibilityMap = _detailsDao.listDetailsVisibility(vm.getId());

List<UserVmDetailVO> details = new ArrayList<UserVmDetailVO>();
for (Map.Entry<String, String> entry : detailsStr.entrySet()) {
boolean display = !hiddenDetails.contains(entry.getKey()) && visibilityMap.getOrDefault(entry.getKey(), true);
details.add(new UserVmDetailVO(vm.getId(), entry.getKey(), entry.getValue(), display));
}

_detailsDao.saveDetails(details);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ public interface DomainRouterDao extends GenericDao<DomainRouterVO, Long> {
*/
public List<DomainRouterVO> listRunningByDomain(Long id);


public void saveDetails(DomainRouterVO vm);

public void saveDetails(DomainRouterVO vm, List<String> hiddenDetails);

/**
* gets the total count by role
* @Param role Router role
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
Expand Down Expand Up @@ -49,7 +48,6 @@
import com.cloud.utils.db.UpdateBuilder;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.UserVmDetailVO;

@Component
@DB
Expand All @@ -73,9 +71,6 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
NetworkOfferingDao _offDao;
protected SearchBuilder<DomainRouterVO> VpcSearch;

@Inject
protected UserVmDetailsDao _detailsDao;

public DomainRouterDaoImpl() {
}

Expand Down Expand Up @@ -455,27 +450,4 @@ public List<DomainRouterVO> listIncludingRemovedByVpcId(long vpcId) {
sc.setParameters("role", Role.VIRTUAL_ROUTER);
return listIncludingRemovedBy(sc);
}

@Override
public void saveDetails(DomainRouterVO vm) {
saveDetails(vm, new ArrayList<String>());
}

@Override
public void saveDetails(DomainRouterVO vm, List<String> hiddenDetails) {
Map<String, String> detailsStr = vm.getDetails();
if (detailsStr == null) {
return;
}

final Map<String, Boolean> visibilityMap = _detailsDao.listDetailsVisibility(vm.getId());

List<UserVmDetailVO> details = new ArrayList<UserVmDetailVO>();
for (Map.Entry<String, String> entry : detailsStr.entrySet()) {
boolean display = !hiddenDetails.contains(entry.getKey()) && visibilityMap.getOrDefault(entry.getKey(), true);
details.add(new UserVmDetailVO(vm.getId(), entry.getKey(), entry.getValue(), display));
}

_detailsDao.saveDetails(details);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@

public interface SecondaryStorageVmDao extends GenericDao<SecondaryStorageVmVO, Long> {

public void saveDetails(SecondaryStorageVmVO vm);

public void saveDetails(SecondaryStorageVmVO vm, List<String> hiddenDetails);

public List<SecondaryStorageVmVO> getSecStorageVmListInStates(SecondaryStorageVm.Role role, long dataCenterId, State... states);

public List<SecondaryStorageVmVO> getSecStorageVmListInStates(SecondaryStorageVm.Role role, State... states);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


import org.springframework.stereotype.Component;
Expand All @@ -35,9 +34,6 @@
import com.cloud.vm.SecondaryStorageVm;
import com.cloud.vm.SecondaryStorageVmVO;
import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.UserVmDetailVO;

import javax.inject.Inject;

@Component
public class SecondaryStorageVmDaoImpl extends GenericDaoBase<SecondaryStorageVmVO, Long> implements SecondaryStorageVmDao {
Expand All @@ -53,9 +49,6 @@ public class SecondaryStorageVmDaoImpl extends GenericDaoBase<SecondaryStorageVm

protected final Attribute _updateTimeAttr;

@Inject
protected UserVmDetailsDao _detailsDao;

public SecondaryStorageVmDaoImpl() {
DataCenterStatusSearch = createSearchBuilder();
DataCenterStatusSearch.and("dc", DataCenterStatusSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
Expand Down Expand Up @@ -273,27 +266,4 @@ public List<Long> listRunningSecStorageOrderByLoad(SecondaryStorageVm.Role role,

return l;
}

@Override
public void saveDetails(SecondaryStorageVmVO vm) {
saveDetails(vm, new ArrayList<String>());
}

@Override
public void saveDetails(SecondaryStorageVmVO vm, List<String> hiddenDetails) {
Map<String, String> detailsStr = vm.getDetails();
if (detailsStr == null) {
return;
}

final Map<String, Boolean> visibilityMap = _detailsDao.listDetailsVisibility(vm.getId());

List<UserVmDetailVO> details = new ArrayList<UserVmDetailVO>();
for (Map.Entry<String, String> entry : detailsStr.entrySet()) {
boolean display = !hiddenDetails.contains(entry.getKey()) && visibilityMap.getOrDefault(entry.getKey(), true);
details.add(new UserVmDetailVO(vm.getId(), entry.getKey(), entry.getValue(), display));
}

_detailsDao.saveDetails(details);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@

import com.cloud.utils.db.GenericDao;
import com.cloud.vm.UserVmDetailVO;
import com.cloud.vm.VMInstanceVO;

import java.util.List;

public interface UserVmDetailsDao extends GenericDao<UserVmDetailVO, Long>, ResourceDetailsDao<UserVmDetailVO> {

public void saveDetails(VMInstanceVO vm);

public void saveDetails(VMInstanceVO vm, List<String> hiddenDetails);

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,45 @@
import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase;

import com.cloud.vm.UserVmDetailVO;
import com.cloud.vm.VMInstanceVO;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

@Component
public class UserVmDetailsDaoImpl extends ResourceDetailsDaoBase<UserVmDetailVO> implements UserVmDetailsDao {

@Inject
protected UserVmDetailsDao _detailsDao;

@Override
public void addDetail(long resourceId, String key, String value, boolean display) {
super.addDetail(new UserVmDetailVO(resourceId, key, value, display));
}

@Override
public void saveDetails(VMInstanceVO vm) {
saveDetails(vm, new ArrayList<String>());
}

Check warning on line 47 in engine/schema/src/main/java/com/cloud/vm/dao/UserVmDetailsDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/vm/dao/UserVmDetailsDaoImpl.java#L45-L47

Added lines #L45 - L47 were not covered by tests

@Override
public void saveDetails(VMInstanceVO vm, List<String> hiddenDetails) {
Map<String, String> detailsStr = vm.getDetails();

Check warning on line 51 in engine/schema/src/main/java/com/cloud/vm/dao/UserVmDetailsDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/vm/dao/UserVmDetailsDaoImpl.java#L50-L51

Added lines #L50 - L51 were not covered by tests
if (detailsStr == null) {
return;

Check warning on line 53 in engine/schema/src/main/java/com/cloud/vm/dao/UserVmDetailsDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/vm/dao/UserVmDetailsDaoImpl.java#L53

Added line #L53 was not covered by tests
}

final Map<String, Boolean> visibilityMap = _detailsDao.listDetailsVisibility(vm.getId());

Check warning on line 56 in engine/schema/src/main/java/com/cloud/vm/dao/UserVmDetailsDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/vm/dao/UserVmDetailsDaoImpl.java#L56

Added line #L56 was not covered by tests

List<UserVmDetailVO> details = new ArrayList<UserVmDetailVO>();

Check warning on line 58 in engine/schema/src/main/java/com/cloud/vm/dao/UserVmDetailsDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/vm/dao/UserVmDetailsDaoImpl.java#L58

Added line #L58 was not covered by tests
for (Map.Entry<String, String> entry : detailsStr.entrySet()) {
boolean display = !hiddenDetails.contains(entry.getKey()) && visibilityMap.getOrDefault(entry.getKey(), true);
details.add(new UserVmDetailVO(vm.getId(), entry.getKey(), entry.getValue(), display));
}

Check warning on line 62 in engine/schema/src/main/java/com/cloud/vm/dao/UserVmDetailsDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/vm/dao/UserVmDetailsDaoImpl.java#L61-L62

Added lines #L61 - L62 were not covered by tests

_detailsDao.saveDetails(details);
}

Check warning on line 65 in engine/schema/src/main/java/com/cloud/vm/dao/UserVmDetailsDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/vm/dao/UserVmDetailsDaoImpl.java#L64-L65

Added lines #L64 - L65 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ protected Map<String, Object> createProxyInstance(long dataCenterId, VMTemplateV
proxy.setLimitCpuUse(serviceOffering.getLimitCpuUse());
proxy = consoleProxyDao.persist(proxy);
proxy.setDetails(template.getDetails());
consoleProxyDao.saveDetails(proxy);
userVmDetailsDao.saveDetails(proxy);

Check warning on line 723 in server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java#L722-L723

Added lines #L722 - L723 were not covered by tests
try {
virtualMachineManager.allocate(name, template, serviceOffering, networks, plan, null);
} catch (InsufficientCapacityException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import com.cloud.network.vpc.dao.VpcDao;
import com.cloud.utils.validation.ChecksumUtil;
import com.cloud.vm.dao.UserVmDetailsDao;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
Expand Down Expand Up @@ -176,6 +177,8 @@ public class NetworkHelperImpl implements NetworkHelper {
CapacityManager capacityMgr;
@Inject
VpcDao vpcDao;
@Inject
private UserVmDetailsDao userVmDetailsDao;

protected final Map<HypervisorType, ConfigKey<String>> hypervisorsMap = new HashMap<>();

Expand Down Expand Up @@ -557,7 +560,7 @@ public DomainRouterVO deployRouter(final RouterDeploymentDefinition routerDeploy
router = _routerDao.persist(router);

router.setDetails(template.getDetails());
_routerDao.saveDetails(router);
userVmDetailsDao.saveDetails(router);

Check warning on line 563 in server/src/main/java/com/cloud/network/router/NetworkHelperImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/network/router/NetworkHelperImpl.java#L562-L563

Added lines #L562 - L563 were not covered by tests

reallocateRouterNetworks(routerDeploymentDefinition, router, template, null);
router = _routerDao.findById(router.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ protected Map<String, Object> createSecStorageVmInstance(long dataCenterId, Seco
secStorageVm.setLimitCpuUse(serviceOffering.getLimitCpuUse());
secStorageVm = _secStorageVmDao.persist(secStorageVm);
secStorageVm.setDetails(template.getDetails());
_secStorageVmDao.saveDetails(secStorageVm);
_vmDetailsDao.saveDetails(secStorageVm);

Check warning on line 675 in services/secondary-storage/controller/src/main/java/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java

View check run for this annotation

Codecov / codecov/patch

services/secondary-storage/controller/src/main/java/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java#L674-L675

Added lines #L674 - L675 were not covered by tests
try {
_itMgr.allocate(name, template, serviceOffering, networks, plan, null);
secStorageVm = _secStorageVmDao.findById(secStorageVm.getId());
Expand Down

0 comments on commit 9d3550d

Please sign in to comment.