Search in sources :

Example 1 with SwitchNameEntity

use of org.openkilda.dao.entity.SwitchNameEntity in project open-kilda by telstra.

the class SwitchIntegrationService method getCustomSwitchNameFromDatabase.

/**
 * Gets the custom switch name from database.
 *
 * @return the custom switch name from database
 */
public Map<String, String> getCustomSwitchNameFromDatabase() {
    Map<String, String> csNames = new HashMap<String, String>();
    List<SwitchNameEntity> switchNames = switchNameRepository.findAll();
    for (SwitchNameEntity name : switchNames) {
        csNames.put(name.getSwitchDpid(), name.getSwitchName());
    }
    return csNames;
}
Also used : SwitchNameEntity(org.openkilda.dao.entity.SwitchNameEntity) HashMap(java.util.HashMap)

Example 2 with SwitchNameEntity

use of org.openkilda.dao.entity.SwitchNameEntity in project open-kilda by telstra.

the class SwitchService method saveOrUpdateSwitchName.

/**
 * Save or update switch name.
 *
 * @param switchId the switch id
 * @param switchName the switch name
 * @return the SwitchInfo
 */
public SwitchInfo saveOrUpdateSwitchName(String switchId, String switchName) {
    String storageType = applicationSettingService.getApplicationSetting(ApplicationSetting.SWITCH_NAME_STORAGE_TYPE);
    if (storageType.equals(IConstants.StorageType.DATABASE_STORAGE.name())) {
        SwitchNameEntity switchNameEntity = switchNameRepository.findBySwitchDpid(switchId);
        if (switchNameEntity == null) {
            switchNameEntity = new SwitchNameEntity();
        }
        switchNameEntity.setSwitchDpid(switchId);
        switchNameEntity.setSwitchName(switchName);
        switchNameEntity.setUpdatedDate(new Date());
        switchNameRepository.save(switchNameEntity);
        SwitchInfo switchInfo = new SwitchInfo();
        switchInfo.setSwitchId(switchId);
        switchInfo.setName(switchName);
        return switchInfo;
    } else {
        throw new RequestValidationException("Storage-Type in Application Settings is not Database, " + "so switch name can not be updated");
    }
}
Also used : SwitchNameEntity(org.openkilda.dao.entity.SwitchNameEntity) SwitchInfo(org.openkilda.model.SwitchInfo) RequestValidationException(org.usermanagement.exception.RequestValidationException) Date(java.util.Date)

Aggregations

SwitchNameEntity (org.openkilda.dao.entity.SwitchNameEntity)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 SwitchInfo (org.openkilda.model.SwitchInfo)1 RequestValidationException (org.usermanagement.exception.RequestValidationException)1