├── version ├── .gitignore ├── license-template ├── src ├── main │ ├── resources │ │ ├── buildInfo.properties │ │ ├── validation.properties │ │ └── bootstrap.yml │ └── java │ │ └── com │ │ └── dell │ │ └── isg │ │ └── smi │ │ └── service │ │ └── server │ │ ├── configuration │ │ ├── BuildInfo.java │ │ ├── controller │ │ │ ├── RootController.java │ │ │ └── TrapConfigController.java │ │ ├── utilities │ │ │ ├── CustomRecursiveToStringStyle.java │ │ │ └── ConfigurationUtils.java │ │ ├── manager │ │ │ ├── ITrapManager.java │ │ │ ├── TrapManagerImpl.java │ │ │ ├── IConfigurationManager.java │ │ │ └── ConfigurationManagerImpl.java │ │ ├── model │ │ │ ├── MessageKey.java │ │ │ ├── SystemEraseRequest.java │ │ │ ├── ServerRequest.java │ │ │ ├── SystemBiosSettings.java │ │ │ ├── ComponentList.java │ │ │ ├── Attribute.java │ │ │ ├── NestedComponent.java │ │ │ ├── ObjectFactory.java │ │ │ ├── ServerComponent.java │ │ │ ├── SubComponent.java │ │ │ ├── DCIM_BootSourceSetting.java │ │ │ ├── ComponentPredicate.java │ │ │ ├── ConfigureBiosResult.java │ │ │ ├── BiosSetupRequest.java │ │ │ ├── DCIM_BIOSEnumeration.java │ │ │ ├── ServiceResponse.java │ │ │ ├── ServerAndNetworkShareRequest.java │ │ │ ├── ServerAndNetworkShareImageRequest.java │ │ │ └── SystemConfiguration.java │ │ ├── NfsYAMLConfiguration.java │ │ ├── SimpleCORSFilter.java │ │ ├── validators │ │ │ ├── CredentialValidator.java │ │ │ ├── SystemEraseValidator.java │ │ │ ├── ServerRequestValidator.java │ │ │ ├── ComponentListValidator.java │ │ │ ├── ServerAndNetworShareValidator.java │ │ │ ├── ServerAndNetworShareImageRequestValidator.java │ │ │ └── BiosSetupRequestValidator.java │ │ └── Application.java │ │ └── exception │ │ ├── EnumErrorCode.java │ │ ├── NotFoundException.java │ │ ├── BadRequestException.java │ │ └── SCPExceptionHandler.java ├── docs │ └── asciidoc │ │ ├── api-server-configuration-v1.adoc │ │ ├── misc.adoc │ │ └── readme.adoc └── test │ ├── java │ └── com │ │ └── dell │ │ └── isg │ │ └── smi │ │ └── service │ │ └── server │ │ └── configuration │ │ └── manager │ │ ├── Swagger2MarkupTest.java │ │ └── ConfigurationManagerImplTest.java │ └── com │ └── dell │ └── isg │ └── smi │ └── service │ └── configuration │ └── Swagger2MarkupTest.java ├── settings.gradle.example ├── pkg ├── dell-server-configuration-profile.service └── scripts │ └── nfs_tool.sh ├── Dockerfile ├── application.yml ├── .project ├── gradle.properties ├── README.md └── LICENSE /version: -------------------------------------------------------------------------------- 1 | 1.1.0 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | /out/ 4 | /.classpath 5 | .gradle/ 6 | .settings/ 7 | .idea/ 8 | *.iml 9 | -------------------------------------------------------------------------------- /license-template: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-configuration-profile/master/license-template -------------------------------------------------------------------------------- /src/main/resources/buildInfo.properties: -------------------------------------------------------------------------------- 1 | buildInfo.version=1.0 2 | buildInfo.tag=devel 3 | buildInfo.date=10-01-2017_10-14 -------------------------------------------------------------------------------- /src/main/resources/validation.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-configuration-profile/master/src/main/resources/validation.properties -------------------------------------------------------------------------------- /src/docs/asciidoc/api-server-configuration-v1.adoc: -------------------------------------------------------------------------------- 1 | include::{generated}/overview.adoc[] 2 | include::readme.adoc[] 3 | include::{generated}/paths.adoc[] 4 | include::{generated}/definitions.adoc[] 5 | include::misc.adoc[] -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/BuildInfo.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-configuration-profile/master/src/main/java/com/dell/isg/smi/service/server/configuration/BuildInfo.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/exception/EnumErrorCode.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-configuration-profile/master/src/main/java/com/dell/isg/smi/service/server/exception/EnumErrorCode.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/exception/NotFoundException.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-configuration-profile/master/src/main/java/com/dell/isg/smi/service/server/exception/NotFoundException.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/exception/BadRequestException.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-configuration-profile/master/src/main/java/com/dell/isg/smi/service/server/exception/BadRequestException.java -------------------------------------------------------------------------------- /src/docs/asciidoc/misc.adoc: -------------------------------------------------------------------------------- 1 | Licensing 2 | --------- 3 | 4 | This docker microservice is available under the 5 | http://www.apache.org/licenses/LICENSE-2.0.txt[Apache 2.0 License]. 6 | 7 | Support 8 | -------- 9 | 10 | Slack Channel: codecommunity.slack.com -------------------------------------------------------------------------------- /settings.gradle.example: -------------------------------------------------------------------------------- 1 | include ':wsmanlib' 2 | project(':wsmanlib').projectDir = new File(settingsDir, '../wsmanlib') 3 | include ':service-fileshare-services' 4 | project(':service-fileshare-services').projectDir = new File(settingsDir, '../service-fileshare-services/') -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/controller/RootController.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-configuration-profile/master/src/main/java/com/dell/isg/smi/service/server/configuration/controller/RootController.java -------------------------------------------------------------------------------- /src/test/java/com/dell/isg/smi/service/server/configuration/manager/Swagger2MarkupTest.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-configuration-profile/master/src/test/java/com/dell/isg/smi/service/server/configuration/manager/Swagger2MarkupTest.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/utilities/CustomRecursiveToStringStyle.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-configuration-profile/master/src/main/java/com/dell/isg/smi/service/server/configuration/utilities/CustomRecursiveToStringStyle.java -------------------------------------------------------------------------------- /pkg/dell-server-configuration-profile.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=dell-server-configuration-profile 3 | After=syslog.target 4 | 5 | [Service] 6 | User=devuser 7 | ExecStart=/opt/dell/server-configuration-profile/application.jar 8 | SuccessExitStatus=143 9 | 10 | [Install] 11 | WantedBy=multi-user.target -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jre 2 | VOLUME /tmp 3 | ADD build/libs/dell-server-configuration-profile*.jar app.jar 4 | COPY pkg/scripts/* /scripts/ 5 | COPY pkg/scripts/* /opt/dell/smi/scripts/ 6 | COPY application.yml /application.yml 7 | EXPOSE 46018 8 | RUN bash -c 'touch /app.jar' 9 | RUN chmod +x /opt/dell/smi/scripts/nfs_tool.sh 10 | RUN apt-get update -qq && apt-get install -y nfs-common 11 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/manager/ITrapManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.manager; 5 | 6 | import com.dell.isg.smi.adapter.server.model.WsmanCredentials; 7 | 8 | public interface ITrapManager { 9 | 10 | public boolean configureTraps(WsmanCredentials wsmanCredentials, String string) throws Exception; 11 | 12 | 13 | public boolean updateTrapFormat(WsmanCredentials wsmanCredentials, String string) throws Exception; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /application.yml: -------------------------------------------------------------------------------- 1 | #server: 2 | #port: 46018 3 | #ssl: 4 | # keyStore: /security/cacerts/keystore.jks 5 | # keyStorePassword: changeit 6 | # keyPassword: changeit 7 | 8 | logging: 9 | level.root: ERROR 10 | level.com.dell.isg.smi: TRACE 11 | file: /var/log/dell/server-configuration-profile.log 12 | 13 | spring: 14 | #application: 15 | #name: SERVER-CONFIG 16 | jackson: 17 | serialization-inclusion : non_null 18 | 19 | nfs_script_file: 20 | script_name: nfs_tool.sh 21 | script_directory: /opt/dell/smi/scripts 22 | 23 | #eureka: 24 | #client: 25 | #serviceUrl: 26 | #defaultZone: http://service-registry:8600/eureka/ 27 | 28 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | smi-service-dell-server-configuration-profile 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.buildship.core.gradleprojectbuilder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.buildship.core.gradleprojectnature 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 46018 3 | --- 4 | 5 | spring: 6 | profiles: default 7 | application: 8 | name: SERVER-CONFIG 9 | cloud: 10 | bus: 11 | enabled: false 12 | consul: 13 | enabled: false 14 | config: 15 | enabled: false 16 | --- 17 | 18 | spring: 19 | profiles: consul 20 | application: 21 | name: SERVER-CONFIG 22 | cloud: 23 | consul: 24 | discovery: 25 | preferIpAddress: true 26 | enabled: true 27 | host: service-registry 28 | port: 8500 29 | config: 30 | prefix: config 31 | profileSeparator: '::' 32 | format: YAML 33 | data-key: data 34 | fail-fast: true -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | version=1.0 2 | dockerTag=devel 3 | buildInfo.licenseControl.runChecks=true 4 | buildInfo.licenseControl.autoDiscover=true 5 | buildInfo.build.name=com.dell.isg.smi:service-server-configuration 6 | systemProp.sonar.host.url=https://sonarqube.com 7 | systemProp.sonar.organization=rackhd-smi 8 | systemProp.sonar.login=##sonarqubeLogin-placeholder## 9 | bintrayRepo=docs 10 | bintrayUserOrg=rackhd 11 | bintrayVcsUrl=https://bintray.com/rackhd/docs/apidoc 12 | bintrayUser=##bintray-user-placeholder## 13 | bintrayApiKey=##bintray-api-key-placeholder## 14 | versionWsmanlib=1.0.61 15 | versionWsmanClient=1.0.37 16 | versionCommonsElm=1.0.82 17 | versionCommonsUtilities=1.0.32 18 | versionCommonsModel=1.0.97 19 | versionAdapterServer=1.0.81 20 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/model/MessageKey.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.model; 5 | 6 | /** 7 | * @author Muqeeth_Kowkab 8 | * 9 | */ 10 | public enum MessageKey { 11 | 12 | INVALID_REQUEST("Invalid.request"), REQUEST_SUBMITTED("Request.submitted"), REQUEST_PROCESS_FAILED("Request.process.failed"), FAILED_INIT("Failed.Initialization"), REQUEST_SUCCESS("Request.success"); 13 | 14 | private String messageKey; 15 | 16 | 17 | MessageKey(String messageKey) { 18 | this.messageKey = messageKey; 19 | } 20 | 21 | 22 | public String getMessageKey() { 23 | return messageKey; 24 | } 25 | 26 | 27 | public void setMessageKey(String messageKey) { 28 | this.messageKey = messageKey; 29 | } 30 | 31 | 32 | public String getKey() { 33 | return this.messageKey; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/manager/TrapManagerImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.manager; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Component; 8 | 9 | import com.dell.isg.smi.adapter.server.config.IConfigAdapter; 10 | import com.dell.isg.smi.adapter.server.model.WsmanCredentials; 11 | 12 | @Component 13 | public class TrapManagerImpl implements ITrapManager { 14 | 15 | @Autowired 16 | IConfigAdapter configAdapter; 17 | 18 | 19 | @Override 20 | public boolean configureTraps(WsmanCredentials wsmanCredentials, String trapDestination) throws Exception { 21 | return configAdapter.configureTraps(wsmanCredentials, trapDestination); 22 | } 23 | 24 | 25 | @Override 26 | public boolean updateTrapFormat(WsmanCredentials wsmanCredentials, String trapFormat) throws Exception { 27 | return configAdapter.updateTrapFormat(wsmanCredentials, trapFormat); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/model/SystemEraseRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.model; 5 | 6 | import com.dell.isg.smi.commons.model.common.Credential; 7 | import io.swagger.annotations.ApiModelProperty; 8 | 9 | /** 10 | * @author Muqeeth_Kowkab 11 | * 12 | */ 13 | 14 | public class SystemEraseRequest { 15 | 16 | @ApiModelProperty(value = "Credential", required = false) 17 | private Credential credential; 18 | 19 | @ApiModelProperty(value = "List of components to be earsed. BIOS_RESET_DEFULT, EMBEDDED_DIAGNOSTICS_ERASE, OS_DRIVERPACK_ERASE, IDRAC_DEFAULT and LC_DATA_ERASE") 20 | private String[] componentNames; 21 | 22 | public Credential getCredential() { 23 | return credential; 24 | } 25 | 26 | public void setCredential(Credential credential) { 27 | this.credential = credential; 28 | } 29 | 30 | public String[] getComponentNames() { 31 | return componentNames; 32 | } 33 | 34 | public void setComponentNames(String[] componentNames) { 35 | this.componentNames = componentNames; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/NfsYAMLConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration; 5 | 6 | import org.springframework.boot.context.properties.ConfigurationProperties; 7 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | @Configuration 11 | @EnableConfigurationProperties 12 | @ConfigurationProperties(prefix = "nfs_script_file") 13 | public class NfsYAMLConfiguration { 14 | 15 | private String script_name; 16 | private String script_directory; 17 | 18 | 19 | /** 20 | * @return the script_name 21 | */ 22 | public String getScript_name() { 23 | return script_name; 24 | } 25 | 26 | 27 | /** 28 | * @param script_name the script_name to set 29 | */ 30 | public void setScript_name(String script_name) { 31 | this.script_name = script_name; 32 | } 33 | 34 | 35 | /** 36 | * @return the script_directory 37 | */ 38 | public String getScript_directory() { 39 | return script_directory; 40 | } 41 | 42 | 43 | /** 44 | * @param script_directory the script_directory to set 45 | */ 46 | public void setScript_directory(String script_directory) { 47 | this.script_directory = script_directory; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/exception/SCPExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dell.isg.smi.service.server.exception; 5 | 6 | import java.util.Locale; 7 | 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.context.support.ResourceBundleMessageSource; 10 | import org.springframework.http.HttpHeaders; 11 | import org.springframework.http.HttpStatus; 12 | import org.springframework.http.ResponseEntity; 13 | import org.springframework.http.converter.HttpMessageNotReadableException; 14 | import org.springframework.web.bind.annotation.ControllerAdvice; 15 | import org.springframework.web.bind.annotation.ExceptionHandler; 16 | 17 | import com.dell.isg.smi.service.server.configuration.model.ServiceResponse; 18 | 19 | /** 20 | * @author mkowkab 21 | * 22 | */ 23 | @ControllerAdvice 24 | public class SCPExceptionHandler{ 25 | 26 | @Autowired 27 | ResourceBundleMessageSource messageSource; 28 | 29 | @ExceptionHandler(value={IllegalArgumentException.class, IllegalStateException.class, HttpMessageNotReadableException.class}) 30 | protected ResponseEntity handleException(RuntimeException ex) { 31 | String errorMessage = messageSource.getMessage("Invalid.request", null, Locale.getDefault()); 32 | ServiceResponse serviceResponse = new ServiceResponse(HttpStatus.BAD_REQUEST, errorMessage); 33 | return new ResponseEntity(serviceResponse, new HttpHeaders(), serviceResponse.getStatus()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/SimpleCORSFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration; 5 | 6 | import java.io.IOException; 7 | 8 | import javax.servlet.Filter; 9 | import javax.servlet.FilterChain; 10 | import javax.servlet.FilterConfig; 11 | import javax.servlet.ServletException; 12 | import javax.servlet.ServletRequest; 13 | import javax.servlet.ServletResponse; 14 | import javax.servlet.http.HttpServletResponse; 15 | 16 | import org.springframework.stereotype.Component; 17 | 18 | /** 19 | * @author Muqeeth.Kowkab 20 | * 21 | */ 22 | @Component 23 | public class SimpleCORSFilter implements Filter { 24 | 25 | public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { 26 | HttpServletResponse response = (HttpServletResponse) res; 27 | response.setHeader("Access-Control-Allow-Origin", "*"); 28 | response.setHeader("Access-Control-Allow-Methods", "PULL, POST, GET, OPTIONS, DELETE"); 29 | response.setHeader("Access-Control-Max-Age", "3600"); 30 | response.setHeader("Access-Control-Allow-Headers", "x-requested-with"); 31 | response.setHeader("Access-Control-Allow-Headers", "Content-Type, api_key, Authorization"); 32 | chain.doFilter(req, res); 33 | } 34 | 35 | 36 | public void init(FilterConfig filterConfig) { 37 | } 38 | 39 | 40 | public void destroy() { 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/validators/CredentialValidator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.validators; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.stereotype.Component; 9 | import org.springframework.validation.Errors; 10 | import org.springframework.validation.ValidationUtils; 11 | import org.springframework.validation.Validator; 12 | 13 | import com.dell.isg.smi.commons.model.common.Credential; 14 | import com.dell.isg.smi.service.server.configuration.utilities.ConfigurationUtils; 15 | 16 | /** 17 | * @author Muqeeth_Kowkab 18 | * 19 | */ 20 | @Component 21 | public class CredentialValidator implements Validator { 22 | 23 | private static final Logger logger = LoggerFactory.getLogger(CredentialValidator.class.getName()); 24 | 25 | 26 | @Override 27 | public boolean supports(Class clazz) { 28 | return Credential.class.isAssignableFrom(clazz); 29 | } 30 | 31 | 32 | @Override 33 | public void validate(Object target, Errors errors) { 34 | logger.info("Validating Credential request"); 35 | Credential obj = (Credential) target; 36 | 37 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address", "NotEmpty.serverIP"); 38 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userName", "NotEmpty.serverUsername"); 39 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "NotEmpty.serverPassword"); 40 | 41 | String address = obj.getAddress(); 42 | 43 | if (!ConfigurationUtils.validateIPAddress(address)) { 44 | errors.rejectValue("address", "NotReachable.serverIP"); 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/validators/SystemEraseValidator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.validators; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.validation.Errors; 11 | import org.springframework.validation.ValidationUtils; 12 | import org.springframework.validation.Validator; 13 | 14 | import com.dell.isg.smi.commons.model.common.Credential; 15 | import com.dell.isg.smi.service.server.configuration.model.SystemEraseRequest; 16 | 17 | /** 18 | * @author Muqeeth_Kowkab 19 | * 20 | */ 21 | @Component 22 | public class SystemEraseValidator implements Validator { 23 | 24 | @Autowired 25 | CredentialValidator credentialValidator; 26 | 27 | private static final Logger logger = LoggerFactory.getLogger(SystemEraseValidator.class.getName()); 28 | 29 | @Override 30 | public boolean supports(Class clazz) { 31 | return SystemEraseRequest.class.isAssignableFrom(clazz); 32 | } 33 | 34 | @Override 35 | public void validate(Object target, Errors errors) { 36 | logger.info("Validating System Erase request"); 37 | SystemEraseRequest obj = (SystemEraseRequest) target; 38 | 39 | Credential credential = obj.getCredential(); 40 | 41 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "credential", "Missing.object.Credential"); 42 | 43 | if (null != credential) { 44 | try { 45 | errors.pushNestedPath("credential"); 46 | ValidationUtils.invokeValidator(credentialValidator, credential, errors); 47 | } finally { 48 | errors.popNestedPath(); 49 | } 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/validators/ServerRequestValidator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.validators; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.stereotype.Component; 9 | import org.springframework.validation.Errors; 10 | import org.springframework.validation.ValidationUtils; 11 | import org.springframework.validation.Validator; 12 | 13 | import com.dell.isg.smi.service.server.configuration.model.ServerRequest; 14 | import com.dell.isg.smi.service.server.configuration.utilities.ConfigurationUtils; 15 | 16 | /** 17 | * @author Muqeeth.Kowkab 18 | * 19 | */ 20 | @Component 21 | public class ServerRequestValidator implements Validator { 22 | 23 | private static final Logger logger = LoggerFactory.getLogger(ServerRequestValidator.class.getName()); 24 | 25 | @Override 26 | public boolean supports(Class clazz) { 27 | return ServerRequest.class.isAssignableFrom(clazz); 28 | } 29 | 30 | @Override 31 | public void validate(Object target, Errors errors) { 32 | logger.info("Validating ServerRequest"); 33 | 34 | ServerRequest obj = (ServerRequest) target; 35 | 36 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "serverIP", "NotEmpty.serverIP"); 37 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "serverUsername", "NotEmpty.serverUsername"); 38 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "serverPassword", "NotEmpty.serverPassword"); 39 | 40 | String serverIPAddress = obj.getServerIP(); 41 | 42 | if (!ConfigurationUtils.validateIPAddress(serverIPAddress)) { 43 | errors.rejectValue("serverIP", "NotReachable.serverIP"); 44 | } 45 | 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/model/ServerRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.model; 5 | 6 | import io.swagger.annotations.ApiModel; 7 | import io.swagger.annotations.ApiModelProperty; 8 | 9 | /** 10 | * @author Muqeeth_Kowkab 11 | * 12 | */ 13 | @ApiModel(value = "ServerRequest", description = "Captures input details of PowerEdge server ") 14 | public class ServerRequest { 15 | 16 | @ApiModelProperty(value = "Server IP address.", dataType = "string", required = true, position=1) 17 | private String serverIP; 18 | 19 | @ApiModelProperty(value = "Server username.", dataType = "string", required = true, position=2) 20 | private String serverUsername; 21 | 22 | @ApiModelProperty(value = "Server password.", dataType = "string", required = true, position=3) 23 | private String serverPassword; 24 | 25 | /** 26 | * @return the serverIP 27 | */ 28 | public String getServerIP() { 29 | return serverIP; 30 | } 31 | 32 | /** 33 | * @param serverIP the serverIP to set 34 | */ 35 | public void setServerIP(String serverIP) { 36 | this.serverIP = serverIP; 37 | } 38 | 39 | /** 40 | * @return the serverUsername 41 | */ 42 | public String getServerUsername() { 43 | return serverUsername; 44 | } 45 | 46 | /** 47 | * @param serverUsername the serverUsername to set 48 | */ 49 | public void setServerUsername(String serverUsername) { 50 | this.serverUsername = serverUsername; 51 | } 52 | 53 | /** 54 | * @return the serverPassword 55 | */ 56 | public String getServerPassword() { 57 | return serverPassword; 58 | } 59 | 60 | /** 61 | * @param serverPassword the serverPassword to set 62 | */ 63 | public void setServerPassword(String serverPassword) { 64 | this.serverPassword = serverPassword; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/test/com/dell/isg/smi/service/configuration/Swagger2MarkupTest.java: -------------------------------------------------------------------------------- 1 | package com.dell.isg.smi.service.configuration; 2 | 3 | import java.io.IOException; 4 | 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.test.context.ContextConfiguration; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | import org.springframework.test.context.web.WebAppConfiguration; 12 | import org.springframework.test.web.servlet.MockMvc; 13 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 14 | import org.springframework.web.context.WebApplicationContext; 15 | 16 | import com.dell.isg.smi.service.server.configuration.Application; 17 | 18 | import io.github.robwin.swagger2markup.Swagger2MarkupConverter; 19 | 20 | //@WebAppConfiguration 21 | //@RunWith(SpringJUnit4ClassRunner.class) 22 | //@ContextConfiguration(classes = Application.class) 23 | public class Swagger2MarkupTest { 24 | 25 | private static final String API_URI = "http://localhost:46018/v2/api-docs?group=server-configuration"; 26 | 27 | @Autowired 28 | private WebApplicationContext context; 29 | 30 | private MockMvc mockMvc; 31 | 32 | 33 | // @Before 34 | public void setUp() throws Exception { 35 | this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build(); 36 | } 37 | 38 | 39 | // @Test 40 | public void convertSwaggerToAsciiDoc() throws IOException { 41 | 42 | Swagger2MarkupConverter.from(API_URI).build().intoFolder("src/docs/asciidoc/generated"); 43 | 44 | // Swagger2MarkupResultHandler.Builder builder = Swagger2MarkupResultHandler 45 | // .outputDirectory(outputDirForFormat("asciidoc")); 46 | // mockMvc.perform(get(API_URI).accept(MediaType.APPLICATION_JSON)) 47 | // .andDo(builder.build()) 48 | // .andExpect(status().isOk()); 49 | 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/model/SystemBiosSettings.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.model; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | import com.fasterxml.jackson.annotation.JsonInclude; 11 | import com.fasterxml.jackson.annotation.JsonInclude.Include; 12 | 13 | /** 14 | * @author Muqeeth.Kowkab 15 | * 16 | */ 17 | @JsonInclude(Include.NON_DEFAULT) 18 | public class SystemBiosSettings { 19 | 20 | private List attributes; 21 | 22 | private Map> possibleValuesForAttributes; 23 | 24 | private List bootSourceSettings; 25 | 26 | /** 27 | * @return the attributes 28 | */ 29 | public List getAttributes() { 30 | return attributes; 31 | } 32 | 33 | /** 34 | * @param attributes the attributes to set 35 | */ 36 | public void setAttributes(List attributes) { 37 | this.attributes = attributes; 38 | } 39 | 40 | /** 41 | * @return the possibleValuesForAttributes 42 | */ 43 | public Map> getPossibleValuesForAttributes() { 44 | return possibleValuesForAttributes; 45 | } 46 | 47 | /** 48 | * @param possibleValuesForAttributes the possibleValuesForAttributes to set 49 | */ 50 | public void setPossibleValuesForAttributes(Map> possibleValuesForAttributes) { 51 | this.possibleValuesForAttributes = possibleValuesForAttributes; 52 | } 53 | 54 | /** 55 | * @return the bootSourceSettings 56 | */ 57 | public List getBootSourceSettings() { 58 | return bootSourceSettings; 59 | } 60 | 61 | /** 62 | * @param bootSourceSettings the bootSourceSettings to set 63 | */ 64 | public void setBootSourceSettings(List bootSourceSettings) { 65 | this.bootSourceSettings = bootSourceSettings; 66 | } 67 | 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/model/ComponentList.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.model; 5 | 6 | import java.util.List; 7 | 8 | import javax.validation.constraints.NotNull; 9 | 10 | import com.dell.isg.smi.service.server.configuration.model.ServerComponent; 11 | 12 | import io.swagger.annotations.ApiModel; 13 | import io.swagger.annotations.ApiModelProperty; 14 | 15 | /** 16 | * @author Muqeeth_Kowkab 17 | * 18 | */ 19 | 20 | @ApiModel(value = "ComponentList", description = "This has ServerAndNetworkShareRequest for Network and Server Details and List of ServerComponents") 21 | public class ComponentList { 22 | 23 | @ApiModelProperty(value = "ServerAndNetworkShareRequest has the details of Network and DELL Servers", required = true) 24 | @NotNull(message = "serverAndNetworkShareRequest cannot be null") 25 | private ServerAndNetworkShareRequest serverAndNetworkShareRequest; 26 | 27 | @ApiModelProperty(value = "List of ServerComponents", required = true) 28 | private List serverComponents; 29 | 30 | @ApiModelProperty(value = "Force Update of Attributes in Configuration if found") 31 | private boolean forceUpdate; 32 | 33 | 34 | /** 35 | * @return the serverAndNetworkShareRequest 36 | */ 37 | public ServerAndNetworkShareRequest getServerAndNetworkShareRequest() { 38 | return serverAndNetworkShareRequest; 39 | } 40 | 41 | 42 | /** 43 | * @param serverAndNetworkShareRequest the serverAndNetworkShareRequest to set 44 | */ 45 | public void setServerAndNetworkShareRequest(ServerAndNetworkShareRequest serverAndNetworkShareRequest) { 46 | this.serverAndNetworkShareRequest = serverAndNetworkShareRequest; 47 | } 48 | 49 | 50 | /** 51 | * @return the serverComponents 52 | */ 53 | public List getServerComponents() { 54 | return serverComponents; 55 | } 56 | 57 | 58 | /** 59 | * @param serverComponents the serverComponents to set 60 | */ 61 | public void setServerComponents(List serverComponents) { 62 | this.serverComponents = serverComponents; 63 | } 64 | 65 | public boolean isForceUpdate() 66 | { 67 | return forceUpdate; 68 | } 69 | 70 | public void setForceUpdate(final boolean forceUpdate) 71 | { 72 | this.forceUpdate = forceUpdate; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/validators/ComponentListValidator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | /** 5 | * 6 | */ 7 | package com.dell.isg.smi.service.server.configuration.validators; 8 | 9 | import java.util.List; 10 | 11 | import org.apache.commons.collections.CollectionUtils; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.stereotype.Component; 16 | import org.springframework.validation.Errors; 17 | import org.springframework.validation.ValidationUtils; 18 | import org.springframework.validation.Validator; 19 | 20 | import com.dell.isg.smi.service.server.configuration.model.ComponentList; 21 | import com.dell.isg.smi.service.server.configuration.model.ServerAndNetworkShareRequest; 22 | import com.dell.isg.smi.service.server.configuration.model.ServerComponent; 23 | 24 | /** 25 | * @author Muqeeth_Kowkab 26 | * 27 | */ 28 | @Component 29 | public class ComponentListValidator implements Validator { 30 | 31 | @Autowired 32 | ServerAndNetworShareValidator serverAndNetworkShareValidator; 33 | 34 | private static final Logger logger = LoggerFactory.getLogger(ComponentListValidator.class.getName()); 35 | 36 | 37 | @Override 38 | public boolean supports(Class clazz) { 39 | return ComponentList.class.isAssignableFrom(clazz); 40 | } 41 | 42 | 43 | @Override 44 | public void validate(Object target, Errors errors) { 45 | logger.info("Validating ComponentListValidator request"); 46 | 47 | ComponentList obj = (ComponentList) target; 48 | 49 | ServerAndNetworkShareRequest serverAndNetworkShareRequest = obj.getServerAndNetworkShareRequest(); 50 | 51 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "serverAndNetworkShareRequest", "Missing.object.ServerAndNetworkShareRequest"); 52 | 53 | 54 | if (null != serverAndNetworkShareRequest) { 55 | try { 56 | errors.pushNestedPath("serverAndNetworkShareRequest"); 57 | ValidationUtils.invokeValidator(serverAndNetworkShareValidator, obj.getServerAndNetworkShareRequest(), errors); 58 | } finally { 59 | errors.popNestedPath(); 60 | } 61 | } 62 | 63 | List serverComponents = obj.getServerComponents(); 64 | 65 | if (CollectionUtils.isEmpty(serverComponents)) { 66 | errors.rejectValue("serverComponents", "Missing.object.ServerComponent"); 67 | } 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/manager/IConfigurationManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.manager; 5 | 6 | import java.util.List; 7 | 8 | import com.dell.isg.smi.commons.model.common.Credential; 9 | import com.dell.isg.smi.service.server.configuration.model.BiosSetupRequest; 10 | import com.dell.isg.smi.service.server.configuration.model.ComponentList; 11 | import com.dell.isg.smi.service.server.configuration.model.ConfigureBiosResult; 12 | import com.dell.isg.smi.service.server.configuration.model.ServerAndNetworkShareImageRequest; 13 | import com.dell.isg.smi.service.server.configuration.model.ServerAndNetworkShareRequest; 14 | import com.dell.isg.smi.service.server.configuration.model.ServerComponent; 15 | import com.dell.isg.smi.service.server.configuration.model.ServerRequest; 16 | import com.dell.isg.smi.service.server.configuration.model.SystemBiosSettings; 17 | import com.dell.isg.smi.service.server.configuration.model.SystemEraseRequest; 18 | import com.dell.isg.smi.wsman.model.XmlConfig; 19 | 20 | public interface IConfigurationManager { 21 | 22 | public XmlConfig importConfiguration(ServerAndNetworkShareRequest serverAndNetworkShareRequest) throws Exception; 23 | 24 | public XmlConfig exportConfiguration(ServerAndNetworkShareRequest serverAndNetworkShareRequest, String exportMode) 25 | throws Exception; 26 | 27 | public List getComponents(ServerAndNetworkShareRequest request) throws Exception; 28 | 29 | public List updateComponents(ComponentList request, boolean forceUpdate) throws Exception; 30 | 31 | public Boolean initializeSCPService(ServerAndNetworkShareRequest request) throws Exception; 32 | 33 | public Object previewConfiguration(ServerAndNetworkShareRequest request) throws Exception; 34 | 35 | public XmlConfig exportInventory(ServerAndNetworkShareRequest request) throws Exception; 36 | 37 | public XmlConfig factoryConfiguration(ServerAndNetworkShareRequest request) throws Exception; 38 | 39 | public XmlConfig backupServerImage(ServerAndNetworkShareImageRequest request) throws Exception; 40 | 41 | public XmlConfig restoreServerImage(ServerAndNetworkShareImageRequest request) throws Exception; 42 | 43 | public String testShareAccessablity(ServerAndNetworkShareRequest request) throws Exception; 44 | 45 | public XmlConfig wipeLifeController(Credential request) throws Exception; 46 | 47 | public XmlConfig systemEraseServer(SystemEraseRequest request) throws Exception; 48 | 49 | public SystemBiosSettings getBiosSettings(ServerRequest request) throws Exception; 50 | 51 | public ConfigureBiosResult configureBios(BiosSetupRequest request) throws Exception; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/model/Attribute.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.model; 5 | 6 | import javax.xml.bind.annotation.*; 7 | 8 | import com.fasterxml.jackson.annotation.JsonInclude; 9 | import com.fasterxml.jackson.annotation.JsonInclude.Include; 10 | 11 | import io.swagger.annotations.ApiModel; 12 | import io.swagger.annotations.ApiModelProperty; 13 | 14 | @ApiModel(value = "Attribute", description = "This has the attribute name and value of a component.") 15 | @JsonInclude(Include.NON_DEFAULT) 16 | @XmlAccessorType(XmlAccessType.FIELD) 17 | @XmlType(name = "", propOrder = { "value" }) 18 | @XmlRootElement(name = "Attribute") 19 | public class Attribute { 20 | 21 | @ApiModelProperty(value = "Attribute Name", required = true) 22 | @XmlAttribute(name = "Name", required = true) 23 | protected String name; 24 | 25 | @ApiModelProperty(value = "Attribute Value", required = true) 26 | @XmlValue 27 | protected String value; 28 | 29 | 30 | /** 31 | * Gets the value of the value property. 32 | * 33 | * @return possible object is {@link String } 34 | * 35 | */ 36 | public String getValue() { 37 | return value; 38 | } 39 | 40 | 41 | /** 42 | * Sets the value of the value property. 43 | * 44 | * @param value allowed object is {@link String } 45 | * 46 | */ 47 | public void setValue(String value) { 48 | this.value = value; 49 | } 50 | 51 | 52 | /** 53 | * Gets the value of the name property. 54 | * 55 | * @return possible object is {@link String } 56 | * 57 | */ 58 | public String getName() { 59 | return name; 60 | } 61 | 62 | 63 | /** 64 | * Sets the value of the name property. 65 | * 66 | * @param value allowed object is {@link String } 67 | * 68 | */ 69 | public void setName(String value) { 70 | this.name = value; 71 | } 72 | 73 | @Override 74 | public boolean equals(final Object o) 75 | { 76 | if (this == o) 77 | { 78 | return true; 79 | } 80 | if (!(o instanceof Attribute)) 81 | { 82 | return false; 83 | } 84 | 85 | final Attribute attribute = (Attribute) o; 86 | 87 | if (!getName().equals(attribute.getName())) 88 | { 89 | return false; 90 | } 91 | return getValue().equals(attribute.getValue()); 92 | } 93 | 94 | @Override 95 | public int hashCode() 96 | { 97 | int result = getName().hashCode(); 98 | result = 31 * result + getValue().hashCode(); 99 | return result; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/validators/ServerAndNetworShareValidator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.validators; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.stereotype.Component; 9 | import org.springframework.validation.Errors; 10 | import org.springframework.validation.ValidationUtils; 11 | import org.springframework.validation.Validator; 12 | 13 | import com.dell.isg.smi.service.server.configuration.model.ServerAndNetworkShareRequest; 14 | import com.dell.isg.smi.service.server.configuration.utilities.ConfigurationUtils; 15 | 16 | /** 17 | * @author Muqeeth_Kowkab 18 | * 19 | */ 20 | @Component 21 | public class ServerAndNetworShareValidator implements Validator { 22 | 23 | private static final Logger logger = LoggerFactory.getLogger(ServerAndNetworShareValidator.class.getName()); 24 | 25 | 26 | @Override 27 | public boolean supports(Class clazz) { 28 | return ServerAndNetworkShareRequest.class.isAssignableFrom(clazz); 29 | } 30 | 31 | 32 | @Override 33 | public void validate(Object target, Errors errors) { 34 | logger.info("Validating Server and network details request"); 35 | ServerAndNetworkShareRequest obj = (ServerAndNetworkShareRequest) target; 36 | 37 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "serverIP", "NotEmpty.serverIP"); 38 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "serverUsername", "NotEmpty.serverUsername"); 39 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "serverPassword", "NotEmpty.serverPassword"); 40 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shareType", "NotEmpty.shareType"); 41 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shareName", "NotEmpty.shareName"); 42 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shareAddress", "NotEmpty.shareAddress"); 43 | // ValidationUtils.rejectIfEmptyOrWhitespace(errors, "fileName", "NotEmpty.fileName"); 44 | 45 | 46 | int shareType = obj.getShareType(); 47 | 48 | if (shareType ==2) { 49 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shareUsername", "NotEmpty.shareUsername"); 50 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "sharePassword", "NotEmpty.sharePassword"); 51 | } 52 | 53 | 54 | String serverIPAddress = obj.getServerIP(); 55 | String shareAddress = obj.getShareAddress(); 56 | 57 | if (!ConfigurationUtils.validateIPAddress(serverIPAddress)) { 58 | errors.rejectValue("serverIP", "NotReachable.serverIP"); 59 | } 60 | 61 | if (!ConfigurationUtils.validateIPAddress(shareAddress)) { 62 | errors.rejectValue("shareAddress", "NotReachable.shareAddress"); 63 | } 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/validators/ServerAndNetworShareImageRequestValidator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.validators; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.stereotype.Component; 9 | import org.springframework.validation.Errors; 10 | import org.springframework.validation.ValidationUtils; 11 | import org.springframework.validation.Validator; 12 | 13 | import com.dell.isg.smi.service.server.configuration.model.ServerAndNetworkShareImageRequest; 14 | import com.dell.isg.smi.service.server.configuration.utilities.ConfigurationUtils; 15 | 16 | /** 17 | * @author Muqeeth_Kowkab 18 | * 19 | */ 20 | @Component 21 | public class ServerAndNetworShareImageRequestValidator implements Validator { 22 | 23 | private static final Logger logger = LoggerFactory.getLogger(ServerAndNetworShareImageRequestValidator.class.getName()); 24 | 25 | 26 | @Override 27 | public boolean supports(Class clazz) { 28 | return ServerAndNetworkShareImageRequest.class.isAssignableFrom(clazz); 29 | } 30 | 31 | 32 | @Override 33 | public void validate(Object target, Errors errors) { 34 | logger.info("Validating Server and network details request"); 35 | ServerAndNetworkShareImageRequest obj = (ServerAndNetworkShareImageRequest) target; 36 | 37 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "serverIP", "NotEmpty.serverIP"); 38 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "serverUsername", "NotEmpty.serverUsername"); 39 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "serverPassword", "NotEmpty.serverPassword"); 40 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shareType", "NotEmpty.shareType"); 41 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shareName", "NotEmpty.shareName"); 42 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shareAddress", "NotEmpty.shareAddress"); 43 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "imageName", "NotEmpty.imageName"); 44 | 45 | 46 | int shareType = obj.getShareType(); 47 | 48 | if (shareType ==2) { 49 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "shareUsername", "NotEmpty.shareUsername"); 50 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "sharePassword", "NotEmpty.sharePassword"); 51 | } 52 | 53 | 54 | String serverIPAddress = obj.getServerIP(); 55 | String shareAddress = obj.getShareAddress(); 56 | 57 | if (!ConfigurationUtils.validateIPAddress(serverIPAddress)) { 58 | errors.rejectValue("serverIP", "NotReachable.ipAddress"); 59 | } 60 | 61 | if (!ConfigurationUtils.validateIPAddress(shareAddress)) { 62 | errors.rejectValue("shareAddress", "NotReachable.ipAddress"); 63 | } 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/model/NestedComponent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.model; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import javax.xml.bind.annotation.XmlAccessType; 9 | import javax.xml.bind.annotation.XmlAccessorType; 10 | import javax.xml.bind.annotation.XmlAttribute; 11 | import javax.xml.bind.annotation.XmlElement; 12 | import javax.xml.bind.annotation.XmlType; 13 | 14 | import com.fasterxml.jackson.annotation.JsonInclude; 15 | import com.fasterxml.jackson.annotation.JsonInclude.Include; 16 | 17 | import io.swagger.annotations.ApiModel; 18 | import io.swagger.annotations.ApiModelProperty; 19 | 20 | @ApiModel(value = "NestedComponent", description = "This has FQDD of the nested component and its respective list of Attribute") 21 | @JsonInclude(Include.NON_DEFAULT) 22 | @XmlAccessorType(XmlAccessType.FIELD) 23 | @XmlType(name = "", propOrder = { "attributes" }) 24 | public class NestedComponent { 25 | 26 | @ApiModelProperty(value = "Fully Qualified Device Descriptor (FQDD).", dataType = "string", required = false) 27 | @XmlAttribute(name = "FQDD", required = true) 28 | protected String fqdd; 29 | 30 | @ApiModelProperty(value = "List of Attributes", required = false) 31 | @XmlElement(name = "Attribute", required = true) 32 | protected List attributes; 33 | 34 | 35 | public List getAttributes() { 36 | if (attributes == null) { 37 | attributes = new ArrayList(); 38 | } 39 | return this.attributes; 40 | } 41 | 42 | 43 | /** 44 | * @param attributes the attribute to set 45 | */ 46 | public void setAttributes(List attributes) { 47 | this.attributes = attributes; 48 | } 49 | 50 | 51 | /** 52 | * Gets the value of the fqdd property. 53 | * 54 | * @return possible object is {@link String } 55 | * 56 | */ 57 | public String getFQDD() { 58 | return fqdd; 59 | } 60 | 61 | 62 | /** 63 | * Sets the value of the fqdd property. 64 | * 65 | * @param value allowed object is {@link String } 66 | * 67 | */ 68 | public void setFQDD(String value) { 69 | this.fqdd = value; 70 | } 71 | 72 | @Override 73 | public boolean equals(final Object o) 74 | { 75 | if (this == o) 76 | { 77 | return true; 78 | } 79 | if (!(o instanceof NestedComponent)) 80 | { 81 | return false; 82 | } 83 | 84 | final NestedComponent that = (NestedComponent) o; 85 | 86 | if (!fqdd.equals(that.fqdd)) 87 | { 88 | return false; 89 | } 90 | return getAttributes().equals(that.getAttributes()); 91 | } 92 | 93 | @Override 94 | public int hashCode() 95 | { 96 | int result = fqdd.hashCode(); 97 | result = 31 * result + getAttributes().hashCode(); 98 | return result; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/validators/BiosSetupRequestValidator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.validators; 5 | 6 | import java.text.ParseException; 7 | import java.text.SimpleDateFormat; 8 | import java.util.Date; 9 | 10 | import org.apache.commons.lang3.StringUtils; 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.stereotype.Component; 15 | import org.springframework.validation.Errors; 16 | import org.springframework.validation.ValidationUtils; 17 | import org.springframework.validation.Validator; 18 | 19 | import com.dell.isg.smi.service.server.configuration.model.BiosSetupRequest; 20 | import com.dell.isg.smi.service.server.configuration.model.ServerRequest; 21 | import com.dell.isg.smi.service.server.configuration.utilities.ConfigurationUtils; 22 | 23 | /** 24 | * @author Muqeeth.Kowkab 25 | * 26 | */ 27 | @Component 28 | public class BiosSetupRequestValidator implements Validator { 29 | 30 | private static final Logger logger = LoggerFactory.getLogger(BiosSetupRequestValidator.class.getName()); 31 | 32 | @Autowired 33 | ServerRequestValidator serverRequestValidator; 34 | 35 | 36 | @Override 37 | public boolean supports(Class clazz) { 38 | return BiosSetupRequest.class.isAssignableFrom(clazz); 39 | } 40 | 41 | 42 | @Override 43 | public void validate(Object target, Errors errors) { 44 | logger.info("Validating BiosSetup request"); 45 | 46 | BiosSetupRequest obj = (BiosSetupRequest) target; 47 | 48 | ServerRequest serverRequest = obj.getServerRequest(); 49 | 50 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "serverRequest", "Missing.object.serverRequest"); 51 | 52 | if (null != serverRequest) { 53 | try { 54 | errors.pushNestedPath("serverRequest"); 55 | ValidationUtils.invokeValidator(serverRequestValidator, obj.getServerRequest(), errors); 56 | } finally { 57 | errors.popNestedPath(); 58 | } 59 | } 60 | 61 | String scheduledStartTime = obj.getScheduledStartTime(); 62 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "scheduledStartTime", "Missing.ScheduledStartTime"); 63 | String untilTime = obj.getUntilTime(); 64 | 65 | if (StringUtils.isNotBlank(scheduledStartTime) && !StringUtils.equals(scheduledStartTime, "TIME_NOW") 66 | && !ConfigurationUtils.validateTime(scheduledStartTime)){ 67 | errors.rejectValue("scheduledStartTime", "Invalid.ScheduledStartTime.Format"); 68 | } 69 | if (StringUtils.isNotBlank(untilTime) && !ConfigurationUtils.validateTime(untilTime)) { 70 | errors.rejectValue("untilTime", "Invalid.UntilTime.Format"); 71 | } 72 | 73 | if (StringUtils.isNotBlank(scheduledStartTime) && StringUtils.isNotBlank(untilTime) 74 | && !ConfigurationUtils.validateEndTimeAfterStartTime(scheduledStartTime, untilTime)) { 75 | errors.rejectValue("untilTime", "Invalid.StartEndTime.Range"); 76 | } 77 | 78 | int rebootJobType = obj.getRebootJobType(); 79 | 80 | if (rebootJobType <=0 || rebootJobType >3) { 81 | errors.rejectValue("untilTime", "Invalid.RebootJobType"); 82 | } 83 | 84 | 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/model/ObjectFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | // 5 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 6 | // See http://java.sun.com/xml/jaxb 7 | // Any modifications to this file will be lost upon recompilation of the source schema. 8 | // Generated on: 2016.11.02 at 04:49:32 PM CDT 9 | // 10 | 11 | package com.dell.isg.smi.service.server.configuration.model; 12 | 13 | import javax.xml.bind.annotation.XmlRegistry; 14 | 15 | /** 16 | * This object contains factory methods for each Java content interface and Java element interface generated in the com.dell.isg.smi.service.server.configuration.model.test 17 | * package. 18 | *

19 | * An ObjectFactory allows you to programatically construct new instances of the Java representation for XML content. The Java representation of XML content can consist of schema 20 | * derived interfaces and classes representing the binding of schema type definitions, element declarations and model groups. Factory methods for each of these are provided in this 21 | * class. 22 | * 23 | */ 24 | @XmlRegistry 25 | public class ObjectFactory { 26 | 27 | /** 28 | * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.dell.isg.smi.service.server.configuration.model.test 29 | * 30 | */ 31 | public ObjectFactory() { 32 | } 33 | 34 | 35 | /** 36 | * Create an instance of {@link SystemConfiguration } 37 | * 38 | */ 39 | public SystemConfiguration createSystemConfiguration() { 40 | return new SystemConfiguration(); 41 | } 42 | 43 | 44 | /** 45 | * Create an instance of {@link SystemConfiguration.Component } 46 | * 47 | */ 48 | public ServerComponent createSystemConfigurationComponent() { 49 | return new ServerComponent(); 50 | } 51 | 52 | 53 | /** 54 | * Create an instance of {@link SystemConfiguration.Component.SubComponent } 55 | * 56 | */ 57 | public SubComponent createSubComponent() { 58 | return new SubComponent(); 59 | } 60 | 61 | 62 | /** 63 | * Create an instance of {@link SystemConfiguration.Component.InnerComponent.NestedComponent } 64 | * 65 | */ 66 | public NestedComponent createSystemConfigurationNestedComponent() { 67 | return new NestedComponent(); 68 | } 69 | 70 | 71 | /** 72 | * Create an instance of {@link SystemConfiguration.Component.Attribute } 73 | * 74 | */ 75 | public Attribute createSystemConfigurationComponentAttribute() { 76 | return new Attribute(); 77 | } 78 | 79 | 80 | /** 81 | * Create an instance of {@link SystemConfiguration.Component.InnerComponent.Attribute } 82 | * 83 | */ 84 | public Attribute createSubComponentAttribute() { 85 | return new Attribute(); 86 | } 87 | 88 | 89 | /** 90 | * Create an instance of {@link NestedComponent.Attribute } 91 | * 92 | */ 93 | public Attribute createNestedComponentAttribute() { 94 | return new Attribute(); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/Application.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration; 5 | 6 | import static springfox.documentation.builders.PathSelectors.regex; 7 | 8 | import java.util.Locale; 9 | 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.SpringApplication; 12 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 13 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 14 | import org.springframework.context.annotation.Bean; 15 | import org.springframework.context.annotation.ComponentScan; 16 | import org.springframework.context.annotation.Configuration; 17 | import org.springframework.context.support.ResourceBundleMessageSource; 18 | import org.springframework.scheduling.annotation.EnableAsync; 19 | import org.springframework.web.servlet.LocaleResolver; 20 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 21 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 22 | import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; 23 | import org.springframework.web.servlet.i18n.SessionLocaleResolver; 24 | 25 | import com.jayway.jsonpath.spi.json.JacksonJsonProvider; 26 | import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider; 27 | 28 | import springfox.documentation.builders.ApiInfoBuilder; 29 | import springfox.documentation.spi.DocumentationType; 30 | import springfox.documentation.spring.web.plugins.Docket; 31 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 32 | 33 | /** 34 | * @author Muqeeth_Kowkab 35 | * 36 | */ 37 | @Configuration 38 | @EnableAutoConfiguration 39 | @EnableSwagger2 40 | @EnableDiscoveryClient 41 | @EnableAsync 42 | @ComponentScan("com.dell.isg.smi") 43 | public class Application extends WebMvcConfigurerAdapter { 44 | 45 | public static void main(String[] args) { 46 | SpringApplication.run(Application.class, args); 47 | } 48 | 49 | @Autowired 50 | private BuildInfo buildInfo; 51 | 52 | @Bean 53 | public LocaleResolver localeResolver() { 54 | SessionLocaleResolver slr = new SessionLocaleResolver(); 55 | slr.setDefaultLocale(Locale.ENGLISH); 56 | return slr; 57 | } 58 | 59 | @Bean 60 | public LocaleChangeInterceptor localeChangeInterceptor() { 61 | LocaleChangeInterceptor lci = new LocaleChangeInterceptor(); 62 | lci.setParamName("lang"); 63 | return lci; 64 | } 65 | 66 | @Bean 67 | public ResourceBundleMessageSource messageSource() { 68 | ResourceBundleMessageSource ms = new ResourceBundleMessageSource(); 69 | ms.setBasename("validation"); 70 | ms.setUseCodeAsDefaultMessage(true); 71 | return ms; 72 | } 73 | 74 | @Bean 75 | public com.jayway.jsonpath.Configuration jsonPathConfiguration() { 76 | com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder() 77 | .mappingProvider(new JacksonMappingProvider()).jsonProvider(new JacksonJsonProvider()).build(); 78 | 79 | return configuration; 80 | 81 | } 82 | 83 | @Override 84 | public void addInterceptors(InterceptorRegistry registry) { 85 | registry.addInterceptor(localeChangeInterceptor()); 86 | } 87 | 88 | @Bean 89 | public Docket newsApi() { 90 | return new Docket(DocumentationType.SWAGGER_2).groupName("serverConfiguration").apiInfo(new ApiInfoBuilder() 91 | .title("SMI Microservice : Server Configuration Profile- WSMAN").version(buildInfo.toString()).build()) 92 | .select().paths(regex("/api.*")).build(); 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/model/ServerComponent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.model; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import javax.xml.bind.annotation.XmlAccessType; 9 | import javax.xml.bind.annotation.XmlAccessorType; 10 | import javax.xml.bind.annotation.XmlAttribute; 11 | import javax.xml.bind.annotation.XmlElement; 12 | import javax.xml.bind.annotation.XmlType; 13 | 14 | import com.fasterxml.jackson.annotation.JsonInclude; 15 | import com.fasterxml.jackson.annotation.JsonInclude.Include; 16 | 17 | import io.swagger.annotations.ApiModel; 18 | import io.swagger.annotations.ApiModelProperty; 19 | 20 | /** 21 | * @author Muqeeth_Kowkab 22 | * 23 | */ 24 | @ApiModel(value = "ServerComponent", description = "This has the Parent Fully Qualified Device Descriptor (FQDD), Attributes and SubComponents") 25 | @JsonInclude(Include.NON_DEFAULT) 26 | @XmlAccessorType(XmlAccessType.FIELD) 27 | @XmlType(name = "", propOrder = { "attributes", "subComponents" }) 28 | public class ServerComponent { 29 | 30 | @ApiModelProperty(value = "Fully Qualified Device Descriptor (FQDD).", dataType = "string", required = true) 31 | @XmlAttribute(name = "FQDD", required = true) 32 | protected String fqdd; 33 | 34 | @ApiModelProperty(value = "List of Attributes", required = true) 35 | @XmlElement(name = "Attribute", required = true) 36 | protected List attributes; 37 | 38 | @ApiModelProperty(value = "List of SubComponent", required = false) 39 | @XmlElement(name = "Component") 40 | protected List subComponents; 41 | 42 | 43 | /** 44 | * @param attribute the attributes to set 45 | */ 46 | public void setAttributes(List attribute) { 47 | this.attributes = attribute; 48 | } 49 | 50 | 51 | /** 52 | * @return the Attributes 53 | */ 54 | public List getAttributes() { 55 | if (attributes == null) { 56 | attributes = new ArrayList(); 57 | } 58 | return this.attributes; 59 | } 60 | 61 | 62 | /** 63 | * @return the innerComponents 64 | */ 65 | public List getSubComponents() { 66 | if (subComponents == null) { 67 | subComponents = new ArrayList(); 68 | } 69 | return this.subComponents; 70 | } 71 | 72 | 73 | /** 74 | * @param subComponents the subComponents to set 75 | */ 76 | public void setSubComponents(List subComponents) { 77 | this.subComponents = subComponents; 78 | } 79 | 80 | 81 | /** 82 | * Gets the value of the fqdd property. 83 | * 84 | * @return possible object is {@link String } 85 | * 86 | */ 87 | public String getFQDD() { 88 | return fqdd; 89 | } 90 | 91 | 92 | /** 93 | * Sets the value of the fqdd property. 94 | * 95 | * @param value allowed object is {@link String } 96 | * 97 | */ 98 | public void setFQDD(String value) { 99 | this.fqdd = value; 100 | } 101 | 102 | @Override 103 | public boolean equals(final Object o) 104 | { 105 | if (this == o) 106 | { 107 | return true; 108 | } 109 | if (!(o instanceof ServerComponent)) 110 | { 111 | return false; 112 | } 113 | 114 | final ServerComponent component = (ServerComponent) o; 115 | 116 | if (!fqdd.equals(component.fqdd)) 117 | { 118 | return false; 119 | } 120 | if (!getAttributes().equals(component.getAttributes())) 121 | { 122 | return false; 123 | } 124 | return getSubComponents().equals(component.getSubComponents()); 125 | } 126 | 127 | @Override 128 | public int hashCode() 129 | { 130 | int result = fqdd.hashCode(); 131 | result = 31 * result + getAttributes().hashCode(); 132 | result = 31 * result + getSubComponents().hashCode(); 133 | return result; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/model/SubComponent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.model; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import javax.xml.bind.annotation.XmlAccessType; 9 | import javax.xml.bind.annotation.XmlAccessorType; 10 | import javax.xml.bind.annotation.XmlAttribute; 11 | import javax.xml.bind.annotation.XmlElement; 12 | import javax.xml.bind.annotation.XmlType; 13 | 14 | import com.fasterxml.jackson.annotation.JsonInclude; 15 | import com.fasterxml.jackson.annotation.JsonInclude.Include; 16 | 17 | import io.swagger.annotations.ApiModel; 18 | import io.swagger.annotations.ApiModelProperty; 19 | 20 | /** 21 | * @author Muqeeth_Kowkab 22 | * 23 | */ 24 | 25 | @ApiModel(value = "SubComponent", description = "This has the attributes of the SubComponent and the Nested Components") 26 | @JsonInclude(Include.NON_DEFAULT) 27 | @XmlAccessorType(XmlAccessType.FIELD) 28 | @XmlType(name = "", propOrder = { "attributes", "nestedComponents" }) 29 | public class SubComponent { 30 | 31 | @ApiModelProperty(value = "Fully Qualified Device Descriptor (FQDD).", dataType = "string", required = false) 32 | @XmlAttribute(name = "FQDD", required = true) 33 | protected String fqdd; 34 | 35 | @ApiModelProperty(value = "List of Attributes", required = false) 36 | @XmlElement(name = "Attribute") 37 | protected List attributes; 38 | 39 | @ApiModelProperty(value = "List of Nested Component.", required = false) 40 | @XmlElement(name = "Component") 41 | protected List nestedComponents; 42 | 43 | 44 | // public List getComponent() { 45 | // if (component == null) { 46 | // component = new ArrayList(); 47 | // } 48 | // return this.component; 49 | // } 50 | 51 | /** 52 | * @return the nestedComponents 53 | */ 54 | public List getNestedComponents() { 55 | if (nestedComponents == null) { 56 | nestedComponents = new ArrayList(); 57 | } 58 | return this.nestedComponents; 59 | } 60 | 61 | 62 | /** 63 | * @param nestedComponents the nestedComponents to set 64 | */ 65 | public void setNestedComponents(List nestedComponents) { 66 | this.nestedComponents = nestedComponents; 67 | } 68 | 69 | 70 | public List getAttributes() { 71 | if (attributes == null) { 72 | attributes = new ArrayList(); 73 | } 74 | return this.attributes; 75 | } 76 | 77 | 78 | /** 79 | * @param attribute the attribute to set 80 | */ 81 | public void setAttributes(List attributes) { 82 | this.attributes = attributes; 83 | } 84 | 85 | 86 | /** 87 | * Gets the value of the fqdd property. 88 | * 89 | * @return possible object is {@link String } 90 | * 91 | */ 92 | public String getFQDD() { 93 | return fqdd; 94 | } 95 | 96 | 97 | /** 98 | * Sets the value of the fqdd property. 99 | * 100 | * @param value allowed object is {@link String } 101 | * 102 | */ 103 | public void setFQDD(String value) { 104 | this.fqdd = value; 105 | } 106 | 107 | @Override 108 | public boolean equals(final Object o) 109 | { 110 | if (this == o) 111 | { 112 | return true; 113 | } 114 | if (!(o instanceof SubComponent)) 115 | { 116 | return false; 117 | } 118 | 119 | final SubComponent that = (SubComponent) o; 120 | 121 | if (!fqdd.equals(that.fqdd)) 122 | { 123 | return false; 124 | } 125 | if (!getAttributes().equals(that.getAttributes())) 126 | { 127 | return false; 128 | } 129 | return getNestedComponents().equals(that.getNestedComponents()); 130 | } 131 | 132 | @Override 133 | public int hashCode() 134 | { 135 | int result = fqdd.hashCode(); 136 | result = 31 * result + getAttributes().hashCode(); 137 | result = 31 * result + getNestedComponents().hashCode(); 138 | return result; 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/docs/asciidoc/readme.adoc: -------------------------------------------------------------------------------- 1 | Purpose 2 | ~~~~~~~ 3 | 4 | Microservice For DELL Server Configuration Profile via WSMAN. It export the system configuration from the server to a file on a remote share. It also import the system configuration from a file located on remote share to server. It gives the features to see the DELL servers individual/All configured components in a readable JSON Format with the configured values. It update the server configuration by taking component names and respective attribute values. Complex components like BIOS, RAID, NIC of DELL servers can be easily configured through SCP microservice. 5 | 6 | Provides a REST API retrieval and application of configuration data on Dell 11th Generation and newer servers. 7 | 8 | http://en.community.dell.com/techcenter/extras/m/white_papers/20439335 9 | 10 | How to Use 11 | ~~~~~~~~~~ 12 | 13 | A docker container for this service is avalable at: https://hub.docker.com/r/rackhd/dell-server-configuration-profile/ 14 | 15 | 16 | .... 17 | sudo docker run -p 0.0.0.0:46018:46018 --privileged --name dell-server-configuration-profile -d rackhd/dell-server-configuration-profile:latest 18 | .... 19 | 20 | The service can also start up to bootstrap its configuration from consul. More information about registration with and using advanced configuration settings provided by a Consul K/V store can be found in the online help. 21 | 22 | 23 | Definitions 24 | +++++++++++ 25 | 26 | **shareType** 27 | Type of network share to mount 28 | Possible Values: 0=nfs, 2=cifs 29 | 30 | **shutdownType** 31 | Type of the host shut down before perform the import operation. 32 | Possible Values: Graceful=0, Forced =1, NoReboot=2 33 | 34 | Example Post - Get Components 35 | +++++++++++++++++++++++++++++ 36 | 37 | This operation gives the server system configuration based upon the component names or ALL the configured components if no component names specified in the request. 38 | 39 | http://hostIp:46018/api/1.0/server/configuration/getComponents 40 | 41 | .... 42 | { 43 | "componentNames": ["LifecycleController.Embedded.1", "RAID.Integrated.1-1"], 44 | "fileName": "FileName.xml", 45 | "serverIP": "<>", 46 | "serverPassword": "<>", 47 | "serverUsername": "<>", 48 | "shareAddress": "<>", 49 | "shareName": "<>", 50 | "shareType": 0 51 | } 52 | .... 53 | 54 | Example Post - Export Configuration From a Dell Server 55 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 56 | 57 | 58 | This operation allow user to export the system configuration from the server to file on a remote share. 59 | 60 | http://hostIp:46018/api/1.0/server/configuration/export 61 | 62 | .... 63 | { 64 | "componentNames": [ " " ], 65 | "fileName": "Filename.xml", 66 | "serverIP": "<>", 67 | "serverPassword": "<>", 68 | "serverUsername": "<>", 69 | "shareAddress": "<>", 70 | "shareName": "<>", 71 | "shareType": 0, 72 | "shutdownType": 0 73 | } 74 | .... 75 | 76 | Example Post - Import Configuration to a Dell Server 77 | +++++++++++++++++++++++++++++++++++++++++++++++++++ 78 | 79 | 80 | Imports the configuration from a json file (same format as the file produced in the export call) on the share specified. 81 | 82 | http://hostIp:46018/api/1.0/server/configuration/import 83 | 84 | .... 85 | { 86 | "componentNames": [ " " ], 87 | "fileName": "Filename.xml", 88 | "serverIP": "<>", 89 | "serverPassword": "<>", 90 | "serverUsername": "<>", 91 | "shareAddress": "<>", 92 | "shareName": "<>", 93 | "shareType": 0, 94 | "shutdownType": 0 95 | } 96 | .... 97 | 98 | Example Post - Update a Subset of Components for a Dell Server 99 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 100 | 101 | This operation allow user to update the server system components. The forceUpdate flag is used to force value changes to attributes regardless of if they are commented out in the exported configuration. 102 | 103 | http://hostIp:46018/api/1.0/server/configuration/updatecomponents 104 | 105 | .... 106 | { 107 | "componentNames": ["LifecycleController.Embedded.1", "RAID.Integrated.1-1"], 108 | "fileName": "FileName.xml", 109 | "forceUpdate":false 110 | "serverIP": "<>", 111 | "serverPassword": "<>", 112 | "serverUsername": "<>", 113 | "shareAddress": "<>", 114 | "shareName": "<>", 115 | "shareType": 0 116 | } 117 | .... -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### service-dell-server-configuration-profile 2 | 3 | Exports and imports/applies part or all of a server configuration profile for a Dell server. 4 | 5 | Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved. 6 | 7 | ### Purpose 8 | 9 | Provides a REST API retrieval and application of configuration data on Dell 11th Generation and newer servers. 10 | 11 | http://en.community.dell.com/techcenter/extras/m/white_papers/20439335 12 | 13 | 14 | ### How to use 15 | 16 | A docker container for this service is avalable at: https://hub.docker.com/r/rackhd/dell-server-configuration-profile/ 17 | 18 | #### Startup 19 | ~~~ 20 | sudo docker run -p 0.0.0.0:46018:46018 --privileged --name dell-server-configuration-profile -d rackhd/dell-server-configuration-profile:latest 21 | ~~~ 22 | 23 | #### API Definitions 24 | A Swagger UI is provided by the microservice at http://<>:46018/swagger-ui.html 25 | 26 | #### Definitions 27 | **shareType** 28 | Type of network share to mount 29 | Possible Values: 0=nfs, 2=cifs 30 | 31 | **shutdownType** 32 | Type of the host shut down before perform the import operation. 33 | Possible Values: Graceful=0, Forced =1, NoReboot=2 34 | 35 | --- 36 | 37 | #### Get Components 38 | This operation gives the server system configuration based upon the component names or ALL the configured components if no component names specified in the request. 39 | 40 | ##### Example Post 41 | ~~~ 42 | http://<>:46018/api/1.0/server/configuration/getComponents 43 | { 44 | "componentNames": ["LifecycleController.Embedded.1", "RAID.Integrated.1-1"], 45 | "fileName": "FileName.xml", 46 | "serverIP": "<>", 47 | "serverPassword": "<>", 48 | "serverUsername": "<>", 49 | "shareAddress": "<>", 50 | "shareName": "<>", 51 | "shareType": 0 52 | } 53 | ~~~ 54 | ___ 55 | #### Export Configuration From a Dell Server 56 | This operation allow user to export the system configuration from the server to file on a remote share. 57 | ##### Example Post 58 | ~~~ 59 | http://<>:46018/api/1.0/server/configuration/export 60 | { 61 | "componentNames": [ " " ], 62 | "fileName": "Filename.xml", 63 | "serverIP": "<>", 64 | "serverPassword": "<>", 65 | "serverUsername": "<>", 66 | "shareAddress": "<>", 67 | "shareName": "<>", 68 | "shareType": 0, 69 | "shutdownType": 0 70 | } 71 | ~~~ 72 | ___ 73 | 74 | #### Import Configuration to a Dell Server 75 | Imports the configuration from a json file (same format as the file produced in the export call) on the share specified. 76 | ##### Example Post 77 | ~~~ 78 | http://<>:46018/api/1.0/server/configuration/import 79 | { 80 | "componentNames": [ " " ], 81 | "fileName": "Filename.xml", 82 | "serverIP": "<>", 83 | "serverPassword": "<>", 84 | "serverUsername": "<>", 85 | "shareAddress": "<>", 86 | "shareName": "<>", 87 | "shareType": 0, 88 | "shutdownType": 0 89 | } 90 | ~~~ 91 | ___ 92 | #### Update a Subset of Components for a Dell Server 93 | This operation allow user to update the server system components. The forceUpdate flag is used to force value changes 94 | to attributes regardless of if they are commented out in the exported configuration. 95 | ##### Example Post 96 | ~~~ 97 | http://<>:46018/api/1.0/server/configuration/updatecomponents?forceUpdate=false 98 | { 99 | "componentNames": ["LifecycleController.Embedded.1", "RAID.Integrated.1-1"], 100 | "fileName": "FileName.xml", 101 | "serverIP": "<>", 102 | "serverPassword": "<>", 103 | "serverUsername": "<>", 104 | "shareAddress": "<>", 105 | "shareName": "<>", 106 | "shareType": 0 107 | } 108 | ~~~ 109 | 110 | ### Licensing 111 | This docker microservice is available under the [Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0.txt). 112 | 113 | Source code for this microservice is available in repositories at https://github.com/RackHD. 114 | 115 | The microservice makes use of dependent Jar libraries that may be covered by other licenses. In order to comply with the requirements of applicable licenses, the source for dependent libraries used by this microservice is available for download at: https://bintray.com/rackhd/binary/download_file?file_path=smi-service-dell-server-configuration-profile-dependency-sources-devel.zip 116 | 117 | Additionally the binary and source jars for all dependent libraries are available for download on Maven Central. 118 | 119 | --- 120 | ### Support 121 | Slack Channel: codecommunity.slack.com 122 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/model/DCIM_BootSourceSetting.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.model; 5 | 6 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 7 | import com.fasterxml.jackson.annotation.JsonProperty; 8 | 9 | /** 10 | * @author Muqeeth.Kowkab 11 | * 12 | */ 13 | @JsonIgnoreProperties(ignoreUnknown=true) 14 | public class DCIM_BootSourceSetting { 15 | 16 | @JsonProperty("BIOSBootString") 17 | private String biosBootString; 18 | 19 | @JsonProperty("BootSourceType") 20 | private String bootSourceType; 21 | 22 | @JsonProperty("BootString") 23 | private String bootString; 24 | 25 | @JsonProperty("CurrentAssignedSequence") 26 | private String currentAssignedSequence; 27 | 28 | @JsonProperty("CurrentEnabledStatus") 29 | private String currentEnabledStatus; 30 | 31 | @JsonProperty("ElementName") 32 | private String elementName; 33 | 34 | @JsonProperty("FailThroughSupported") 35 | private String failThroughSupported; 36 | 37 | @JsonProperty("InstanceID") 38 | private String instanceId; 39 | 40 | @JsonProperty("PendingAssignedSequence") 41 | private String pendingAssignedSequence; 42 | 43 | @JsonProperty("PendingEnabledStatus") 44 | private String pendingEnabledStatus; 45 | 46 | /** 47 | * @return the biosBootString 48 | */ 49 | public String getBiosBootString() { 50 | return biosBootString; 51 | } 52 | 53 | /** 54 | * @param biosBootString the biosBootString to set 55 | */ 56 | public void setBiosBootString(String biosBootString) { 57 | this.biosBootString = biosBootString; 58 | } 59 | 60 | /** 61 | * @return the bootSourceType 62 | */ 63 | public String getBootSourceType() { 64 | return bootSourceType; 65 | } 66 | 67 | /** 68 | * @param bootSourceType the bootSourceType to set 69 | */ 70 | public void setBootSourceType(String bootSourceType) { 71 | this.bootSourceType = bootSourceType; 72 | } 73 | 74 | /** 75 | * @return the bootString 76 | */ 77 | public String getBootString() { 78 | return bootString; 79 | } 80 | 81 | /** 82 | * @param bootString the bootString to set 83 | */ 84 | public void setBootString(String bootString) { 85 | this.bootString = bootString; 86 | } 87 | 88 | /** 89 | * @return the currentAssignedSequence 90 | */ 91 | public String getCurrentAssignedSequence() { 92 | return currentAssignedSequence; 93 | } 94 | 95 | /** 96 | * @param currentAssignedSequence the currentAssignedSequence to set 97 | */ 98 | public void setCurrentAssignedSequence(String currentAssignedSequence) { 99 | this.currentAssignedSequence = currentAssignedSequence; 100 | } 101 | 102 | /** 103 | * @return the currentEnabledStatus 104 | */ 105 | public String getCurrentEnabledStatus() { 106 | return currentEnabledStatus; 107 | } 108 | 109 | /** 110 | * @param currentEnabledStatus the currentEnabledStatus to set 111 | */ 112 | public void setCurrentEnabledStatus(String currentEnabledStatus) { 113 | this.currentEnabledStatus = currentEnabledStatus; 114 | } 115 | 116 | /** 117 | * @return the elementName 118 | */ 119 | public String getElementName() { 120 | return elementName; 121 | } 122 | 123 | /** 124 | * @param elementName the elementName to set 125 | */ 126 | public void setElementName(String elementName) { 127 | this.elementName = elementName; 128 | } 129 | 130 | /** 131 | * @return the failThroughSupported 132 | */ 133 | public String getFailThroughSupported() { 134 | return failThroughSupported; 135 | } 136 | 137 | /** 138 | * @param failThroughSupported the failThroughSupported to set 139 | */ 140 | public void setFailThroughSupported(String failThroughSupported) { 141 | this.failThroughSupported = failThroughSupported; 142 | } 143 | 144 | /** 145 | * @return the instanceId 146 | */ 147 | public String getInstanceId() { 148 | return instanceId; 149 | } 150 | 151 | /** 152 | * @param instanceId the instanceId to set 153 | */ 154 | public void setInstanceId(String instanceId) { 155 | this.instanceId = instanceId; 156 | } 157 | 158 | /** 159 | * @return the pendingAssignedSequence 160 | */ 161 | public String getPendingAssignedSequence() { 162 | return pendingAssignedSequence; 163 | } 164 | 165 | /** 166 | * @param pendingAssignedSequence the pendingAssignedSequence to set 167 | */ 168 | public void setPendingAssignedSequence(String pendingAssignedSequence) { 169 | this.pendingAssignedSequence = pendingAssignedSequence; 170 | } 171 | 172 | /** 173 | * @return the pendingEnabledStatus 174 | */ 175 | public String getPendingEnabledStatus() { 176 | return pendingEnabledStatus; 177 | } 178 | 179 | /** 180 | * @param pendingEnabledStatus the pendingEnabledStatus to set 181 | */ 182 | public void setPendingEnabledStatus(String pendingEnabledStatus) { 183 | this.pendingEnabledStatus = pendingEnabledStatus; 184 | } 185 | 186 | } 187 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/model/ComponentPredicate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.model; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | import org.apache.commons.collections4.CollectionUtils; 11 | import org.apache.commons.collections4.Predicate; 12 | import org.apache.commons.lang3.StringUtils; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | import org.springframework.stereotype.Component; 16 | 17 | /** 18 | * @author Muqeeth_Kowkab 19 | * 20 | */ 21 | @Component 22 | public class ComponentPredicate { 23 | private static final Logger logger = LoggerFactory.getLogger(ComponentPredicate.class.getName()); 24 | 25 | public Predicate filterInstanceIds(List serverBootSourceSettings, List filteredInstanceIds) { 26 | return new Predicate() { 27 | 28 | @Override 29 | public boolean evaluate(String bootDevice) { 30 | if (StringUtils.isBlank(bootDevice) || null == serverBootSourceSettings) { 31 | return false; 32 | } 33 | for (DCIM_BootSourceSetting dcimBootSource: serverBootSourceSettings) { 34 | String serverBootSourceType = dcimBootSource.getBootSourceType(); 35 | if (StringUtils.equals(serverBootSourceType, "IPL") || StringUtils.equals(serverBootSourceType, "BCV")) { 36 | String serverInstanceId = dcimBootSource.getInstanceId(); 37 | String[] parsedStrings = StringUtils.split(serverInstanceId, "#"); 38 | 39 | if (StringUtils.equals(bootDevice, serverInstanceId) 40 | || (StringUtils.equals(parsedStrings[2], bootDevice) 41 | && (StringUtils.equals(parsedStrings[1], "BootSeq") 42 | || (StringUtils.equals(parsedStrings[1], "HddSeq"))))) { 43 | logger.info("filterInstanceId: " + parsedStrings[2]); 44 | filteredInstanceIds.add(serverInstanceId); 45 | return true; 46 | } 47 | } 48 | } 49 | return false; 50 | } 51 | }; 52 | } 53 | 54 | 55 | public Predicate filterAttributes(SystemBiosSettings serverBiosSettings, 56 | Map filteredAttributes) { 57 | return new Predicate() { 58 | 59 | @Override 60 | public boolean evaluate(Attribute requestAttribute) { 61 | if (null == requestAttribute || null == serverBiosSettings) { 62 | return false; 63 | } 64 | Map> possibleValuesMap = serverBiosSettings.getPossibleValuesForAttributes(); 65 | ArrayList serverPossibleValues = possibleValuesMap.get(requestAttribute.getName()); 66 | List serverAttributes = serverBiosSettings.getAttributes(); 67 | 68 | if (CollectionUtils.isNotEmpty(serverPossibleValues) 69 | && serverPossibleValues.contains(requestAttribute.getValue()) && null != serverAttributes) { 70 | 71 | for (Attribute serverAttribute : serverAttributes) { 72 | String serverAttributeName = serverAttribute.getName(); 73 | String serverAttributeValue = serverAttribute.getValue(); 74 | 75 | if (StringUtils.equals(serverAttributeName, requestAttribute.getName()) 76 | && !StringUtils.equals(serverAttributeValue, requestAttribute.getValue())) { 77 | logger.info("filterAttributes:: Request AttributeName: " + requestAttribute.getName()); 78 | filteredAttributes.put(requestAttribute.getName(), requestAttribute.getValue()); 79 | return true; 80 | } 81 | } 82 | } 83 | return false; 84 | } 85 | 86 | }; 87 | } 88 | 89 | 90 | public Predicate filterEnableDisableDevices(List serverBootSourceSettings, 91 | boolean isEnabled) { 92 | return new Predicate() { 93 | 94 | @Override 95 | public boolean evaluate(String bootDevice) { 96 | if (StringUtils.isBlank(bootDevice) || null == serverBootSourceSettings) { 97 | return false; 98 | } 99 | for (DCIM_BootSourceSetting dcimBootSource : serverBootSourceSettings) { 100 | 101 | String serverBootSourceType = dcimBootSource.getBootSourceType(); 102 | 103 | if (StringUtils.equals(serverBootSourceType, "IPL")) { 104 | String serverInstanceId = dcimBootSource.getInstanceId(); 105 | String[] parsedStrings = StringUtils.split(serverInstanceId, "#"); 106 | 107 | if (StringUtils.equals(bootDevice, serverInstanceId) 108 | || (StringUtils.equals(parsedStrings[2], bootDevice))) { 109 | if (isEnabled && StringUtils.contains(dcimBootSource.getCurrentEnabledStatus(), "0")) { 110 | logger.info("filterEnableDisableDevices: " + parsedStrings[2] + " To Enable"); 111 | return true; 112 | } else if (!isEnabled 113 | && StringUtils.contains(dcimBootSource.getCurrentEnabledStatus(), "1")) { 114 | logger.info("filterEnableDisableDevices: " + parsedStrings[2] + " To Disable"); 115 | return true; 116 | } 117 | } 118 | } 119 | } 120 | return false; 121 | } 122 | 123 | }; 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/model/ConfigureBiosResult.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.model; 5 | 6 | import java.util.Map; 7 | 8 | import com.dell.isg.smi.wsman.model.XmlConfig; 9 | import com.fasterxml.jackson.annotation.JsonInclude; 10 | import com.fasterxml.jackson.annotation.JsonInclude.Include; 11 | 12 | import io.swagger.annotations.ApiModelProperty; 13 | 14 | /** 15 | * @author Muqeeth.Kowkab 16 | * 17 | */ 18 | @JsonInclude(Include.NON_DEFAULT) 19 | public class ConfigureBiosResult { 20 | 21 | @ApiModelProperty(value = "JobID", dataType = "string", required = false, position=1) 22 | private String configBiosMessage; 23 | 24 | @ApiModelProperty(value = "JobID", dataType = "string", required = false, position=2) 25 | private String jobId; 26 | 27 | @ApiModelProperty(value = "BIOS Update Attributes Result Message", dataType = "string", required = false, position=3) 28 | private String biosUpdateAttributesResult; 29 | 30 | @ApiModelProperty(value = "BIOS Updated Attributes", required = false, position=4) 31 | private Map updatedAttributes; 32 | 33 | @ApiModelProperty(value = "BIOS BootOrder Sequence Change Message", dataType = "string", required = false, position=5) 34 | private String changeBootOrderSequenceMessage; 35 | 36 | @ApiModelProperty(value = "BIOS HDD Sequence Change Result Message", dataType = "string", required = false, position=6) 37 | private String changeHddSequenceMessage; 38 | 39 | @ApiModelProperty(value = "BIOS Boot Devices Enable Result Message", dataType = "string", required = false, position=7) 40 | private String enableBootDevicesResult; 41 | 42 | @ApiModelProperty(value = "BIOS Boot Devices Disable Result Message", dataType = "string", required = false, position=8) 43 | private String disableBootDevicesResult; 44 | 45 | @ApiModelProperty(value = "The XMLConfig. Which has the details of JobID, Message and Result returned from DELL Server", required = false, position=9) 46 | private XmlConfig xmlConfig; 47 | 48 | /** 49 | * @return the configBiosMessage 50 | */ 51 | public String getConfigBiosMessage() { 52 | return configBiosMessage; 53 | } 54 | 55 | /** 56 | * @param configBiosMessage the configBiosMessage to set 57 | */ 58 | public void setConfigBiosMessage(String configBiosMessage) { 59 | this.configBiosMessage = configBiosMessage; 60 | } 61 | 62 | /** 63 | * @return the jobId 64 | */ 65 | public String getJobId() { 66 | return jobId; 67 | } 68 | 69 | /** 70 | * @param jobId the jobId to set 71 | */ 72 | public void setJobId(String jobId) { 73 | this.jobId = jobId; 74 | } 75 | 76 | /** 77 | * @return the biosUpdateAttributesResult 78 | */ 79 | public String getBiosUpdateAttributesResult() { 80 | return biosUpdateAttributesResult; 81 | } 82 | 83 | /** 84 | * @param biosUpdateAttributesResult the biosUpdateAttributesResult to set 85 | */ 86 | public void setBiosUpdateAttributesResult(String biosUpdateAttributesResult) { 87 | this.biosUpdateAttributesResult = biosUpdateAttributesResult; 88 | } 89 | 90 | /** 91 | * @return the updatedAttributes 92 | */ 93 | public Map getUpdatedAttributes() { 94 | return updatedAttributes; 95 | } 96 | 97 | /** 98 | * @param updatedAttributes the updatedAttributes to set 99 | */ 100 | public void setUpdatedAttributes(Map updatedAttributes) { 101 | this.updatedAttributes = updatedAttributes; 102 | } 103 | 104 | /** 105 | * @return the changeBootOrderSequenceMessage 106 | */ 107 | public String getChangeBootOrderSequenceMessage() { 108 | return changeBootOrderSequenceMessage; 109 | } 110 | 111 | /** 112 | * @param changeBootOrderSequenceMessage the changeBootOrderSequenceMessage to set 113 | */ 114 | public void setChangeBootOrderSequenceMessage(String changeBootOrderSequenceMessage) { 115 | this.changeBootOrderSequenceMessage = changeBootOrderSequenceMessage; 116 | } 117 | 118 | /** 119 | * @return the changeHddSequenceMessage 120 | */ 121 | public String getChangeHddSequenceMessage() { 122 | return changeHddSequenceMessage; 123 | } 124 | 125 | /** 126 | * @param changeHddSequenceMessage the changeHddSequenceMessage to set 127 | */ 128 | public void setChangeHddSequenceMessage(String changeHddSequenceMessage) { 129 | this.changeHddSequenceMessage = changeHddSequenceMessage; 130 | } 131 | 132 | /** 133 | * @return the enableBootDevicesResult 134 | */ 135 | public String getEnableBootDevicesResult() { 136 | return enableBootDevicesResult; 137 | } 138 | 139 | /** 140 | * @param enableBootDevicesResult the enableBootDevicesResult to set 141 | */ 142 | public void setEnableBootDevicesResult(String enableBootDevicesResult) { 143 | this.enableBootDevicesResult = enableBootDevicesResult; 144 | } 145 | 146 | /** 147 | * @return the disableBootDevicesResult 148 | */ 149 | public String getDisableBootDevicesResult() { 150 | return disableBootDevicesResult; 151 | } 152 | 153 | /** 154 | * @param disableBootDevicesResult the disableBootDevicesResult to set 155 | */ 156 | public void setDisableBootDevicesResult(String disableBootDevicesResult) { 157 | this.disableBootDevicesResult = disableBootDevicesResult; 158 | } 159 | 160 | /** 161 | * @return the xmlConfig 162 | */ 163 | public XmlConfig getXmlConfig() { 164 | return xmlConfig; 165 | } 166 | 167 | /** 168 | * @param xmlConfig the xmlConfig to set 169 | */ 170 | public void setXmlConfig(XmlConfig xmlConfig) { 171 | this.xmlConfig = xmlConfig; 172 | } 173 | 174 | 175 | 176 | } 177 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/model/BiosSetupRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.model; 5 | 6 | import java.util.List; 7 | 8 | import io.swagger.annotations.ApiModel; 9 | import io.swagger.annotations.ApiModelProperty; 10 | 11 | /** 12 | * @author Muqeeth.Kowkab 13 | * 14 | */ 15 | @ApiModel(value = "BiosSetupRequest", description = "Captures input details to configure BIOS of Dell Server") 16 | public class BiosSetupRequest { 17 | 18 | @ApiModelProperty(value = "Dell Server Credentials", required = true, position=1) 19 | private ServerRequest serverRequest; 20 | 21 | @ApiModelProperty(value = "List of BIOS Attribute Object. Which include Attibute Name and Attribute Value", required = true, position=2) 22 | private List attributes; 23 | 24 | @ApiModelProperty(value = "List of Boot devices to be ordered in the sequence.", required = false, position=3) 25 | private List biosBootSequenceOrder; 26 | 27 | @ApiModelProperty(value = "List of Hard-Disk Drive devices to be ordered in the sequence.", required = false, position=4) 28 | private List hddSequenceOrder; 29 | 30 | @ApiModelProperty(value = "List of boot devices to enable", required = false, position=5) 31 | private List enableBootDevices; 32 | 33 | @ApiModelProperty(value = "List of boot devices to disable", required = false, position=6) 34 | private List disableBootDevices; 35 | 36 | @ApiModelProperty(value = "Shall contain the requested reboot type: 1 - PowerCycle(cold boot) 2 - Graceful Reboot without forced shutdown 3 - Graceful Reboot with forced shutdown.", 37 | dataType = "uint16",required=true, 38 | position=7) 39 | private int rebootJobType; 40 | 41 | @ApiModelProperty(value = "Schedules the configuration job and the optional reboot job at the specified start time in the format: yyyymmddhhmmss. " 42 | + "A special value of TIME_NOW schedules the job(s) immediately." 43 | + "scheduledStartTime is w.r.t Server time to schedule.",required = true, position=8) 44 | private String scheduledStartTime; 45 | 46 | @ApiModelProperty(value = "End time for the job execution in format: yyyymmddhhmmss. : If this parameter is not NULL, then ScheduledStartTime parameter shall also be specified." 47 | + " NOTE: This parameter has a dependency on ScheduledStartTime parameter. Both ScheduledStartTime and UntilTime parameters define a time window for scheduling the job(s). " 48 | + "After scheduling, jobs are executed within the time window." 49 | + "unitTime is w.r.t Server time to schedule", required=false, position=9) 50 | private String untilTime; 51 | 52 | /** 53 | * @return the serverRequest 54 | */ 55 | public ServerRequest getServerRequest() { 56 | return serverRequest; 57 | } 58 | 59 | /** 60 | * @param serverRequest the serverRequest to set 61 | */ 62 | public void setServerRequest(ServerRequest serverRequest) { 63 | this.serverRequest = serverRequest; 64 | } 65 | 66 | /** 67 | * @return the attributes 68 | */ 69 | public List getAttributes() { 70 | return attributes; 71 | } 72 | 73 | /** 74 | * @param attributes the attributes to set 75 | */ 76 | public void setAttributes(List attributes) { 77 | this.attributes = attributes; 78 | } 79 | 80 | /** 81 | * @return the biosBootSequenceOrder 82 | */ 83 | public List getBiosBootSequenceOrder() { 84 | return biosBootSequenceOrder; 85 | } 86 | 87 | /** 88 | * @param biosBootSequenceOrder the biosBootSequenceOrder to set 89 | */ 90 | public void setBiosBootSequenceOrder(List biosBootSequenceOrder) { 91 | this.biosBootSequenceOrder = biosBootSequenceOrder; 92 | } 93 | 94 | /** 95 | * @return the hddSequenceOrder 96 | */ 97 | public List getHddSequenceOrder() { 98 | return hddSequenceOrder; 99 | } 100 | 101 | /** 102 | * @param hddSequenceOrder the hddSequenceOrder to set 103 | */ 104 | public void setHddSequenceOrder(List hddSequenceOrder) { 105 | this.hddSequenceOrder = hddSequenceOrder; 106 | } 107 | 108 | /** 109 | * @return the enableBootDevices 110 | */ 111 | public List getEnableBootDevices() { 112 | return enableBootDevices; 113 | } 114 | 115 | /** 116 | * @param enableBootDevices the enableBootDevices to set 117 | */ 118 | public void setEnableBootDevices(List enableBootDevices) { 119 | this.enableBootDevices = enableBootDevices; 120 | } 121 | 122 | /** 123 | * @return the disableBootDevices 124 | */ 125 | public List getDisableBootDevices() { 126 | return disableBootDevices; 127 | } 128 | 129 | /** 130 | * @param disableBootDevices the disableBootDevices to set 131 | */ 132 | public void setDisableBootDevices(List disableBootDevices) { 133 | this.disableBootDevices = disableBootDevices; 134 | } 135 | 136 | /** 137 | * @return the rebootJobType 138 | */ 139 | public int getRebootJobType() { 140 | return rebootJobType; 141 | } 142 | 143 | /** 144 | * @param rebootJobType the rebootJobType to set 145 | */ 146 | public void setRebootJobType(int rebootJobType) { 147 | this.rebootJobType = rebootJobType; 148 | } 149 | 150 | /** 151 | * @return the scheduledStartTime 152 | */ 153 | public String getScheduledStartTime() { 154 | return scheduledStartTime; 155 | } 156 | 157 | /** 158 | * @param scheduledStartTime the scheduledStartTime to set 159 | */ 160 | public void setScheduledStartTime(String scheduledStartTime) { 161 | this.scheduledStartTime = scheduledStartTime; 162 | } 163 | 164 | /** 165 | * @return the untilTime 166 | */ 167 | public String getUntilTime() { 168 | return untilTime; 169 | } 170 | 171 | /** 172 | * @param untilTime the untilTime to set 173 | */ 174 | public void setUntilTime(String untilTime) { 175 | this.untilTime = untilTime; 176 | } 177 | 178 | } 179 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/model/DCIM_BIOSEnumeration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.model; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import com.fasterxml.jackson.annotation.JsonFormat; 10 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 11 | import com.fasterxml.jackson.annotation.JsonProperty; 12 | 13 | /** 14 | * @author mkowkab 15 | * 16 | */ 17 | @JsonIgnoreProperties(ignoreUnknown=true) 18 | public class DCIM_BIOSEnumeration { 19 | 20 | @JsonProperty("DisplayOrder") 21 | private String displayOrder; 22 | 23 | @JsonProperty("InstanceID") 24 | private String instanceId; 25 | 26 | @JsonProperty("PendingValue") 27 | private String pendingValue; 28 | 29 | @JsonProperty("PossibleValuesDescription") 30 | @JsonFormat(with=JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY) 31 | private ArrayList possibleValuesDescription; 32 | 33 | @JsonProperty("CurrentValue") 34 | private String currentValue; 35 | 36 | @JsonProperty("FQDD") 37 | private String fqdd; 38 | 39 | @JsonProperty("GroupDisplayName") 40 | private String groupDisplayName; 41 | 42 | @JsonProperty("PossibleValues") 43 | @JsonFormat(with=JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY) 44 | private ArrayList possibleValues; 45 | 46 | @JsonProperty("Dependency") 47 | private String dependency; 48 | 49 | @JsonProperty("GroupID") 50 | private String groupId; 51 | 52 | @JsonProperty("AttributeDisplayName") 53 | private String attributeDisplayName; 54 | 55 | @JsonProperty("AttributeName") 56 | private String attributeName; 57 | 58 | @JsonProperty("IsReadOnly") 59 | private String isReadOnly; 60 | 61 | /** 62 | * @return the displayOrder 63 | */ 64 | public String getDisplayOrder() { 65 | return displayOrder; 66 | } 67 | 68 | /** 69 | * @param displayOrder the displayOrder to set 70 | */ 71 | public void setDisplayOrder(String displayOrder) { 72 | this.displayOrder = displayOrder; 73 | } 74 | 75 | /** 76 | * @return the instanceId 77 | */ 78 | public String getInstanceId() { 79 | return instanceId; 80 | } 81 | 82 | /** 83 | * @param instanceId the instanceId to set 84 | */ 85 | public void setInstanceId(String instanceId) { 86 | this.instanceId = instanceId; 87 | } 88 | 89 | /** 90 | * @return the pendingValue 91 | */ 92 | public String getPendingValue() { 93 | return pendingValue; 94 | } 95 | 96 | /** 97 | * @param pendingValue the pendingValue to set 98 | */ 99 | public void setPendingValue(String pendingValue) { 100 | this.pendingValue = pendingValue; 101 | } 102 | 103 | /** 104 | * @return the possibleValuesDescription 105 | */ 106 | public ArrayList getPossibleValuesDescription() { 107 | return possibleValuesDescription; 108 | } 109 | 110 | /** 111 | * @param possibleValuesDescription the possibleValuesDescription to set 112 | */ 113 | public void setPossibleValuesDescription(ArrayList possibleValuesDescription) { 114 | this.possibleValuesDescription = possibleValuesDescription; 115 | } 116 | 117 | /** 118 | * @return the currentValue 119 | */ 120 | public String getCurrentValue() { 121 | return currentValue; 122 | } 123 | 124 | /** 125 | * @param currentValue the currentValue to set 126 | */ 127 | public void setCurrentValue(String currentValue) { 128 | this.currentValue = currentValue; 129 | } 130 | 131 | /** 132 | * @return the fqdd 133 | */ 134 | public String getFqdd() { 135 | return fqdd; 136 | } 137 | 138 | /** 139 | * @param fqdd the fqdd to set 140 | */ 141 | public void setFqdd(String fqdd) { 142 | this.fqdd = fqdd; 143 | } 144 | 145 | /** 146 | * @return the groupDisplayName 147 | */ 148 | public String getGroupDisplayName() { 149 | return groupDisplayName; 150 | } 151 | 152 | /** 153 | * @param groupDisplayName the groupDisplayName to set 154 | */ 155 | public void setGroupDisplayName(String groupDisplayName) { 156 | this.groupDisplayName = groupDisplayName; 157 | } 158 | 159 | 160 | /** 161 | * @return the possibleValues 162 | */ 163 | public ArrayList getPossibleValues() { 164 | return possibleValues; 165 | } 166 | 167 | /** 168 | * @param possibleValues the possibleValues to set 169 | */ 170 | public void setPossibleValues(ArrayList possibleValues) { 171 | this.possibleValues = possibleValues; 172 | } 173 | 174 | /** 175 | * @return the dependency 176 | */ 177 | public String getDependency() { 178 | return dependency; 179 | } 180 | 181 | /** 182 | * @param dependency the dependency to set 183 | */ 184 | public void setDependency(String dependency) { 185 | this.dependency = dependency; 186 | } 187 | 188 | /** 189 | * @return the groupId 190 | */ 191 | public String getGroupId() { 192 | return groupId; 193 | } 194 | 195 | /** 196 | * @param groupId the groupId to set 197 | */ 198 | public void setGroupId(String groupId) { 199 | this.groupId = groupId; 200 | } 201 | 202 | /** 203 | * @return the attributeDisplayName 204 | */ 205 | public String getAttributeDisplayName() { 206 | return attributeDisplayName; 207 | } 208 | 209 | /** 210 | * @param attributeDisplayName the attributeDisplayName to set 211 | */ 212 | public void setAttributeDisplayName(String attributeDisplayName) { 213 | this.attributeDisplayName = attributeDisplayName; 214 | } 215 | 216 | /** 217 | * @return the attributeName 218 | */ 219 | public String getAttributeName() { 220 | return attributeName; 221 | } 222 | 223 | /** 224 | * @param attributeName the attributeName to set 225 | */ 226 | public void setAttributeName(String attributeName) { 227 | this.attributeName = attributeName; 228 | } 229 | 230 | /** 231 | * @return the isReadOnly 232 | */ 233 | public String getIsReadOnly() { 234 | return isReadOnly; 235 | } 236 | 237 | /** 238 | * @param isReadOnly the isReadOnly to set 239 | */ 240 | public void setIsReadOnly(String isReadOnly) { 241 | this.isReadOnly = isReadOnly; 242 | } 243 | 244 | 245 | } 246 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/model/ServiceResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.model; 5 | 6 | import java.util.List; 7 | 8 | import org.springframework.http.HttpStatus; 9 | 10 | import com.dell.isg.smi.service.server.configuration.model.ServerComponent; 11 | import com.dell.isg.smi.wsman.model.XmlConfig; 12 | import com.fasterxml.jackson.annotation.JsonInclude; 13 | import com.fasterxml.jackson.annotation.JsonInclude.Include; 14 | 15 | import io.swagger.annotations.ApiModel; 16 | import io.swagger.annotations.ApiModelProperty; 17 | 18 | @JsonInclude(Include.NON_DEFAULT) 19 | @ApiModel(value = "ServiceResponse", description = "This has the detailed description of the result of microservice call. It includes Message, errors if any like Validation errors, error message, XMLConfig the result returned from the DELL Servers for the Server Configuration transaction.") 20 | public class ServiceResponse { 21 | 22 | @ApiModelProperty(hidden = true) 23 | private HttpStatus status; 24 | 25 | @ApiModelProperty(value = "Response Message.", dataType = "string", required = false) 26 | private String message; 27 | 28 | @ApiModelProperty(value = "List of Errors.", required = false) 29 | private List errors; 30 | 31 | @ApiModelProperty(value = "Error message", dataType = "string", required = false) 32 | private String error; 33 | 34 | @ApiModelProperty(value = "The XMLConfig. Which has the details of JobID, Message and Result returned from DELL Server", required = false) 35 | private XmlConfig xmlConfig; 36 | 37 | @ApiModelProperty(value = "The ServerComponent. Which has the FQDD, Attributes and nested components", dataType = "string", required = false) 38 | private List serverComponents; 39 | 40 | @ApiModelProperty(value = "The Result. Which has the details of preview import configuration Result returned from DELL Server", required = false) 41 | private Object result; 42 | 43 | @ApiModelProperty(value = "The System BIOS Settings of DELL Server", required = false) 44 | private SystemBiosSettings systemBiosSettings; 45 | 46 | @ApiModelProperty(value = "The Configure BIOS Result", required = false) 47 | private ConfigureBiosResult configureBiosResult; 48 | 49 | public ServiceResponse(HttpStatus status, String message) { 50 | super(); 51 | this.status = status; 52 | this.message = message; 53 | } 54 | 55 | 56 | public ServiceResponse(HttpStatus status, String message, List errors) { 57 | super(); 58 | this.status = status; 59 | this.message = message; 60 | this.errors = errors; 61 | } 62 | 63 | 64 | public ServiceResponse(HttpStatus status, String message, XmlConfig xmlConfig) { 65 | super(); 66 | this.status = status; 67 | this.message = message; 68 | this.setXmlConfig(xmlConfig); 69 | } 70 | 71 | 72 | public ServiceResponse(HttpStatus status, String message, String error) { 73 | super(); 74 | this.status = status; 75 | this.message = message; 76 | this.error = error; 77 | } 78 | 79 | public ServiceResponse(HttpStatus status, String message, Object result) { 80 | super(); 81 | this.status = status; 82 | this.message = message; 83 | this.setXmlConfig(xmlConfig); 84 | } 85 | 86 | 87 | /** 88 | * @return the status 89 | */ 90 | public HttpStatus getStatus() { 91 | return status; 92 | } 93 | 94 | 95 | /** 96 | * @param status the status to set 97 | */ 98 | public void setStatus(HttpStatus status) { 99 | this.status = status; 100 | } 101 | 102 | 103 | /** 104 | * @return the message 105 | */ 106 | public String getMessage() { 107 | return message; 108 | } 109 | 110 | 111 | /** 112 | * @param message the message to set 113 | */ 114 | public void setMessage(String message) { 115 | this.message = message; 116 | } 117 | 118 | 119 | /** 120 | * @return the errors 121 | */ 122 | public List getErrors() { 123 | return errors; 124 | } 125 | 126 | 127 | /** 128 | * @param errors the errors to set 129 | */ 130 | public void setErrors(List errors) { 131 | this.errors = errors; 132 | } 133 | 134 | 135 | public String getError() { 136 | return error; 137 | } 138 | 139 | 140 | public void setError(String error) { 141 | this.error = error; 142 | } 143 | 144 | 145 | public XmlConfig getXmlConfig() { 146 | return xmlConfig; 147 | } 148 | 149 | 150 | public void setXmlConfig(XmlConfig xmlConfig) { 151 | this.xmlConfig = xmlConfig; 152 | } 153 | 154 | public Object getResult() { 155 | return result; 156 | } 157 | 158 | 159 | public void setResult(Object result) { 160 | this.result = result; 161 | } 162 | 163 | 164 | /** 165 | * @return the serverComponents 166 | */ 167 | public List getServerComponents() { 168 | return serverComponents; 169 | } 170 | 171 | 172 | /** 173 | * @param serverComponents the serverComponents to set 174 | */ 175 | public void setServerComponents(List serverComponents) { 176 | this.serverComponents = serverComponents; 177 | } 178 | 179 | 180 | /** 181 | * @return the systemBiosSettings 182 | */ 183 | public SystemBiosSettings getSystemBiosSettings() { 184 | return systemBiosSettings; 185 | } 186 | 187 | 188 | /** 189 | * @param systemBiosSettings the systemBiosSettings to set 190 | */ 191 | public void setSystemBiosSettings(SystemBiosSettings systemBiosSettings) { 192 | this.systemBiosSettings = systemBiosSettings; 193 | } 194 | 195 | 196 | /** 197 | * @return the configureBiosResult 198 | */ 199 | public ConfigureBiosResult getConfigureBiosResult() { 200 | return configureBiosResult; 201 | } 202 | 203 | 204 | /** 205 | * @param configureBiosResult the configureBiosResult to set 206 | */ 207 | public void setConfigureBiosResult(ConfigureBiosResult configureBiosResult) { 208 | this.configureBiosResult = configureBiosResult; 209 | } 210 | 211 | 212 | 213 | } 214 | -------------------------------------------------------------------------------- /pkg/scripts/nfs_tool.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ############################################################# 3 | ## nfs_tool.sh 4 | ## 5 | ##----------------------------------------------------------- 6 | ## Utility to configure the nfs service 7 | ##----------------------------------------------------------- 8 | ## 9 | ## Copyright (c) 2015 Dell Computer Corporation 10 | ## 11 | ############################################################# 12 | 13 | 14 | # This function called from firstBoot.sh 15 | # Creates controller NFS share and directory for remote shares 16 | 17 | function createDefaultShare 18 | { 19 | local -r shareLocal=${LOCAL_SHARE_PATH}/nfs 20 | 21 | local defaultShare=${shareLocal}" *(rw,sync,no_subtree_check,no_root_squash,no_all_squash)" 22 | 23 | if [ -e ${shareLocal} ]; then 24 | echo "Controller file share directory ( ${shareLocal} ) already exists." 25 | else 26 | echo "Creating directory ${shareLocal} for controller file share..." 27 | mkdir -p ${shareLocal} 28 | #change the permissions on shares directory and sub directories 29 | chmod -R 777 /shares 30 | cp -ra /opt/dell/icee/appliance/templates/server/. ${shareLocal} 31 | fi 32 | 33 | local tmp=`exportfs | grep -io ${shareLocal}` 34 | 35 | if [[ -n ${tmp} ]]; then 36 | echo "Controller file share has already been exported." 37 | else 38 | echo "Exporting controller file share..." 39 | echo ${defaultShare} >> /etc/exports 40 | exportfs -a 41 | fi 42 | } 43 | 44 | 45 | function mountRemoteShare 46 | { 47 | local url="" 48 | local credentials="" 49 | local -r mountPoint=${REMOTE_SHARE_PATH}/${shareName} 50 | local -u type=${shareType} 51 | 52 | case "${type}" in 53 | NFS) 54 | url=${shareAddress}:${sharePath} 55 | ;; 56 | CIFS) 57 | url="//${shareAddress}/${sharePath}" 58 | credentials="-o username=${shareUsername},password=${sharePassword}" 59 | ;; 60 | esac 61 | 62 | # check if this share is already mounted 63 | local tmp=`mount | grep ${url}` 64 | if [[ -n ${tmp} ]]; then 65 | if [ "$(echo ${tmp} | cut -d ' ' -f 3)" == ${mountPoint} ]; then 66 | echo "Already mounted: `echo ${tmp} | cut -d ' ' -f 1-5`" 67 | echo " Nothing to do!" 68 | exit 1 69 | fi 70 | fi 71 | 72 | # check if mount point is available 73 | if [ -e ${mountPoint} ]; then 74 | if [ -d ${mountPoint} ]; then 75 | if [ "$(ls -A ${mountPoint})" ]; then 76 | echo "${mountPoint} directory already exists and is not empty." 77 | exit 1 78 | fi 79 | else 80 | echo "${mountPoint} exists and is not a directory." 81 | exit 1 82 | fi 83 | fi 84 | 85 | echo "Creating directory ${mountPoint} for remote file share..." 86 | mkdir -p ${mountPoint} 87 | chmod 777 ${mountPoint} 88 | 89 | echo "Mounting ${shareType} share ( ${url} ) at ${mountPoint}" 90 | mount -t ${shareType} ${credentials} ${url} ${mountPoint} 91 | exit $? 92 | } 93 | 94 | 95 | function unmountRemoteShare 96 | { 97 | if [[ -z ${shareName} ]]; then 98 | echo "Must provide share name" 99 | exit 1 100 | fi 101 | 102 | local mountPoint="" 103 | 104 | if [[ "${shareName}" =~ ^/ ]]; then 105 | mountPoint=${REMOTE_SHARE_PATH}${shareName} 106 | else 107 | mountPoint=${REMOTE_SHARE_PATH}/${shareName} 108 | fi 109 | 110 | echo "Un-mounting remote share ${mountPoint} ..." 111 | 112 | 113 | # check if this share is already mounted 114 | local tmp=`mount | grep "${mountPoint} "` 115 | if [[ -n ${tmp} ]]; then 116 | echo "Un-mounting share: `echo ${tmp} | cut -d ' ' -f 1-5`" 117 | umount ${mountPoint} 118 | rm -rf ${mountPoint} 119 | else 120 | echo "No share currently mounted at: ${mountPoint}" 121 | fi 122 | 123 | exit 0 124 | } 125 | 126 | 127 | function usage 128 | { 129 | echo " --configure|-c (Configure the controllers file share at /shares/local/nfs. No other args required.)" 130 | echo 131 | echo " ****** Mounting/Un-mounting Remote Shares ******" 132 | echo " --name|-n (Share name will be used as mount location folder name)" 133 | echo " --address|-a (IP address of remote share)" 134 | echo " --path|-s (Path of remote share)" 135 | echo " --type|-t (Type of remote share NFS|CIFS)" 136 | echo " --username|-u (User name for remote share access - CIFS only)" 137 | echo " --password|-p (Password for remote share access - CIFS only)" 138 | echo 139 | echo " --unmount|-m (Un-mount a remote share. shareName = mount folder)" 140 | echo 141 | } 142 | 143 | 144 | ######## MAIN ######## 145 | 146 | declare -r LOCAL_SHARE_PATH="/shares/local" 147 | declare -r REMOTE_SHARE_PATH="/shares/remote" 148 | 149 | # Set to defaults for controller share creation 150 | declare shareName="nfs" 151 | declare shareAddress="" 152 | declare sharePath=${LOCAL_SHARE_PATH} 153 | declare -l shareType="nfs" 154 | declare sharePassword="" 155 | declare shareUsername="" 156 | 157 | declare proceed=1 158 | 159 | 160 | if [[ -z "${1}" ]]; then 161 | echo "No arguments specified..." 162 | usage 163 | exit 0 164 | fi 165 | 166 | while true; do 167 | if [ $1 ]; then 168 | case "$1" in 169 | --configure|-c) 170 | createDefaultShare 171 | # Necessary to force exported folder permissions 172 | exec chmod -R 777 ${LOCAL_SHARE_PATH} 173 | exit 0 174 | ;; 175 | --unmount|-m) 176 | shift 177 | shareName=${1} 178 | unmountRemoteShare 179 | exit 0 180 | ;; 181 | --name|-n) 182 | shift 183 | shareName=${1} 184 | ;; 185 | --address|-a) 186 | shift 187 | shareAddress=${1} 188 | ;; 189 | --path|-s) 190 | shift 191 | sharePath=${1} 192 | ;; 193 | --type|-t) 194 | shift 195 | shareType=${1} 196 | ;; 197 | --username|-u) 198 | shift 199 | shareUsername=${1} 200 | ;; 201 | --password|-p) 202 | shift 203 | sharePassword=${1} 204 | ;; 205 | # invalid option 206 | *) 207 | echo "Invalid Option" 208 | ;; 209 | esac 210 | shift 211 | else 212 | break 213 | fi 214 | done 215 | 216 | if [[ -z "${shareName}" ]]; then 217 | echo Share name is required 218 | proceed=0 219 | fi 220 | 221 | if [[ -z "${shareAddress}" ]]; then 222 | echo Share address is required 223 | proceed=0 224 | fi 225 | 226 | if [[ -z "${sharePath}" ]]; then 227 | echo Share path is required 228 | proceed=0 229 | fi 230 | 231 | if [[ -z "${shareType}" ]]; then 232 | echo Share type is required 233 | proceed=0 234 | else 235 | case "${shareType}" in 236 | NFS|nfs) 237 | ;; 238 | CIFS|cifs) 239 | if [[ -z "${shareUsername}" || -z "${sharePassword}" ]]; then 240 | echo "Credentials are required with CIFS share." 241 | proceed=0 242 | fi 243 | ;; 244 | *) 245 | echo "Invalid share type: ${shareType}" 246 | proceed=0 247 | ;; 248 | esac 249 | fi 250 | 251 | if [[ $proceed -eq 0 ]]; then 252 | exit 1 253 | fi 254 | 255 | mountRemoteShare 256 | exit 0 257 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/controller/TrapConfigController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.controller; 5 | 6 | import org.apache.commons.lang3.StringUtils; 7 | import org.apache.commons.lang3.builder.ReflectionToStringBuilder; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.web.bind.annotation.PathVariable; 12 | import org.springframework.web.bind.annotation.RequestBody; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RequestMethod; 15 | import org.springframework.web.bind.annotation.RestController; 16 | 17 | import com.dell.isg.smi.adapter.server.model.WsmanCredentials; 18 | import com.dell.isg.smi.commons.elm.exception.RuntimeCoreException; 19 | import com.dell.isg.smi.commons.utilities.CustomRecursiveToStringStyle; 20 | import com.dell.isg.smi.commons.model.common.Credential; 21 | import com.dell.isg.smi.commons.model.common.ResponseString; 22 | import com.dell.isg.smi.service.server.configuration.manager.ITrapManager; 23 | import com.dell.isg.smi.service.server.exception.BadRequestException; 24 | import com.dell.isg.smi.service.server.exception.EnumErrorCode; 25 | 26 | import io.swagger.annotations.ApiImplicitParam; 27 | import io.swagger.annotations.ApiImplicitParams; 28 | import io.swagger.annotations.ApiOperation; 29 | import io.swagger.annotations.ApiResponse; 30 | import io.swagger.annotations.ApiResponses; 31 | 32 | @RestController 33 | @RequestMapping("/api/1.0/server/configuration/trap") 34 | public class TrapConfigController { 35 | 36 | private static final Logger logger = LoggerFactory.getLogger(TrapConfigController.class); 37 | 38 | @Autowired 39 | ITrapManager trapManagerImpl; 40 | 41 | 42 | @RequestMapping(value = "/configureTraps/{trapDestination}", method = RequestMethod.POST, headers = "Accept=application/json", consumes = "application/json", produces = "application/json") 43 | @ApiOperation(value = "/configureTraps/{trapDestination}", nickname = "traps", notes = "This operation allow user to configure server traps throu wsman.", response = ResponseString.class) 44 | // @ApiImplicitParams({ 45 | // @ApiImplicitParam(name = "Credential", value = "Credential", required = true, dataType = "Credential.class", paramType = "Body", defaultValue = "no default") }) 46 | @ApiResponses(value = { @ApiResponse(code = 200, message = "Success", response = ResponseString.class), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 404, message = "Not Found"), @ApiResponse(code = 500, message = "Failure") }) 47 | public ResponseString configureTraps(@RequestBody Credential credential, @PathVariable("trapDestination") String trapDestination) { 48 | logger.trace("Credential for configuring traps : ", credential.getAddress(), credential.getUserName()); 49 | String result = "Failed to configure the traps."; 50 | if (credential == null || StringUtils.isEmpty(credential.getAddress())) { 51 | BadRequestException badRequestException = new BadRequestException(); 52 | badRequestException.setErrorCode(EnumErrorCode.IOIDENTITY_INVALID_INPUT); 53 | throw badRequestException; 54 | } 55 | 56 | if (trapDestination == null || StringUtils.isEmpty(trapDestination)) { 57 | BadRequestException badRequestException = new BadRequestException(); 58 | badRequestException.setErrorCode(EnumErrorCode.IOIDENTITY_INVALID_INPUT); 59 | throw badRequestException; 60 | } 61 | try { 62 | WsmanCredentials wsmanCredentials = new WsmanCredentials(credential.getAddress(), credential.getUserName(), credential.getPassword()); 63 | boolean status = trapManagerImpl.configureTraps(wsmanCredentials, trapDestination); 64 | if (status) { 65 | result = "Successfully to configure the traps."; 66 | } 67 | } catch (Exception e) { 68 | logger.error("Exception occured in trap configuration : ", e); 69 | RuntimeCoreException runtimeCoreException = new RuntimeCoreException(e); 70 | runtimeCoreException.setErrorCode(EnumErrorCode.ENUM_SERVER_ERROR); 71 | throw runtimeCoreException; 72 | } 73 | logger.trace("Trap Response : ", ReflectionToStringBuilder.toString(result, new CustomRecursiveToStringStyle(99))); 74 | return new ResponseString(result); 75 | } 76 | 77 | 78 | @RequestMapping(value = "/updateTrapFormat/{trapFormat}", method = RequestMethod.POST, headers = "Accept=application/json", consumes = "application/json", produces = "application/json") 79 | @ApiOperation(value = "/updateTrapFormat/{trapFormat}", nickname = "trapFormat", notes = "This operation allow user to update server traps throu wsman.", response = ResponseString.class) 80 | // @ApiImplicitParams({ 81 | // @ApiImplicitParam(name = "Credential", value = "Credential", required = true, dataType = "Credential.class", paramType = "Body", defaultValue = "no default") }) 82 | @ApiResponses(value = { @ApiResponse(code = 200, message = "Success", response = ResponseString.class), @ApiResponse(code = 401, message = "Unauthorized"), @ApiResponse(code = 403, message = "Forbidden"), @ApiResponse(code = 404, message = "Not Found"), @ApiResponse(code = 500, message = "Failure") }) 83 | public ResponseString updateTrapFormat(@RequestBody Credential credential, @PathVariable("trapFormat") String trapFormat) { 84 | logger.trace("Credential for configuring trap format : ", credential.getAddress(), credential.getUserName()); 85 | String result = "Failed to update snmp trap format."; 86 | if (credential == null || StringUtils.isEmpty(credential.getAddress())) { 87 | BadRequestException badRequestException = new BadRequestException(); 88 | badRequestException.setErrorCode(EnumErrorCode.IOIDENTITY_INVALID_INPUT); 89 | throw badRequestException; 90 | } 91 | 92 | if (trapFormat == null || StringUtils.isEmpty(trapFormat)) { 93 | BadRequestException badRequestException = new BadRequestException(); 94 | badRequestException.setErrorCode(EnumErrorCode.IOIDENTITY_INVALID_INPUT); 95 | throw badRequestException; 96 | } 97 | 98 | try { 99 | WsmanCredentials wsmanCredentials = new WsmanCredentials(credential.getAddress(), credential.getUserName(), credential.getPassword()); 100 | boolean status = trapManagerImpl.updateTrapFormat(wsmanCredentials, trapFormat); 101 | if (status) { 102 | result = "Successfully update snmp trap format."; 103 | } 104 | } catch (Exception e) { 105 | logger.error("Exception occured in trap configuration : ", e); 106 | RuntimeCoreException runtimeCoreException = new RuntimeCoreException(e); 107 | runtimeCoreException.setErrorCode(EnumErrorCode.ENUM_SERVER_ERROR); 108 | throw runtimeCoreException; 109 | } 110 | logger.trace("Trap format response : ", ReflectionToStringBuilder.toString(result, new CustomRecursiveToStringStyle(99))); 111 | return new ResponseString(result); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/model/ServerAndNetworkShareRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.model; 5 | 6 | import java.util.List; 7 | 8 | import io.swagger.annotations.ApiModel; 9 | 10 | //import com.wordnik.swagger.annotations.ApiModel; 11 | 12 | import io.swagger.annotations.ApiModelProperty; 13 | 14 | /** 15 | * @author Muqeeth_Kowkab 16 | * 17 | */ 18 | 19 | @ApiModel(value = "ServerAndNetworkShareRequest", description = "Captures input request of server and network share details ") 20 | public class ServerAndNetworkShareRequest { 21 | 22 | @ApiModelProperty(value = "Server IP address.", dataType = "string", required = true) 23 | private String serverIP; 24 | 25 | @ApiModelProperty(value = "Server username.", dataType = "string", required = true) 26 | private String serverUsername; 27 | 28 | @ApiModelProperty(value = "Server password.", dataType = "string", required = true) 29 | private String serverPassword; 30 | 31 | @ApiModelProperty(value = "Type of share: NFS=0, CIFS=2", required = true) 32 | private int shareType; 33 | 34 | @ApiModelProperty(value = "The shared directory name on the server being exported. Not the location.", dataType = "string") 35 | private String shareName; 36 | 37 | @ApiModelProperty(value = "The IP address of the target export server", dataType = "string") 38 | private String shareAddress; 39 | 40 | @ApiModelProperty(value = "The target output file name.", dataType = "string") 41 | private String fileName; 42 | 43 | @ApiModelProperty(value = "Username of share server in the scenario of share type CIFS", dataType = "string") 44 | private String shareUsername; 45 | 46 | @ApiModelProperty(value = "Password of share server in the scenario of share type CIFS.", dataType = "string") 47 | private String sharePassword; 48 | 49 | @ApiModelProperty(hidden = true) 50 | private String filePathName; 51 | 52 | @ApiModelProperty(value = "To identify the component for Import. It identifies the one or more FQDDs. Selective list of FQDDs should be given in comma separated format. Default = ALL") 53 | private List componentNames; 54 | 55 | @ApiModelProperty(value = "Type of the host shut down before perform the import operation. Graceful=0, Forced =1, NoReboot=2. Only applies in importing the configuration to server", dataType = "uint16") 56 | private int shutdownType; 57 | 58 | @ApiModelProperty(hidden = true) 59 | private boolean randomFile; 60 | 61 | @ApiModelProperty(hidden = true) 62 | private String sharePath; 63 | 64 | 65 | /** 66 | * @return the serverIP 67 | */ 68 | public String getServerIP() { 69 | return serverIP; 70 | } 71 | 72 | 73 | /** 74 | * @param serverIP the serverIP to set 75 | */ 76 | public void setServerIP(String serverIP) { 77 | this.serverIP = serverIP; 78 | } 79 | 80 | 81 | /** 82 | * @return the serverUsername 83 | */ 84 | public String getServerUsername() { 85 | return serverUsername; 86 | } 87 | 88 | 89 | /** 90 | * @param serverUsername the serverUsername to set 91 | */ 92 | public void setServerUsername(String serverUsername) { 93 | this.serverUsername = serverUsername; 94 | } 95 | 96 | 97 | /** 98 | * @return the serverPassword 99 | */ 100 | public String getServerPassword() { 101 | return serverPassword; 102 | } 103 | 104 | 105 | /** 106 | * @param serverPassword the serverPassword to set 107 | */ 108 | public void setServerPassword(String serverPassword) { 109 | this.serverPassword = serverPassword; 110 | } 111 | 112 | 113 | /** 114 | * @return the shareType 115 | */ 116 | public int getShareType() { 117 | return shareType; 118 | } 119 | 120 | 121 | /** 122 | * @param shareType the shareType to set 123 | */ 124 | public void setShareType(int shareType) { 125 | this.shareType = shareType; 126 | } 127 | 128 | 129 | /** 130 | * @return the shareName 131 | */ 132 | public String getShareName() { 133 | return shareName; 134 | } 135 | 136 | 137 | /** 138 | * @param shareName the shareName to set 139 | */ 140 | public void setShareName(String shareName) { 141 | this.shareName = shareName; 142 | } 143 | 144 | 145 | /** 146 | * @return the shareAddress 147 | */ 148 | public String getShareAddress() { 149 | return shareAddress; 150 | } 151 | 152 | 153 | /** 154 | * @param shareAddress the shareAddress to set 155 | */ 156 | public void setShareAddress(String shareAddress) { 157 | this.shareAddress = shareAddress; 158 | } 159 | 160 | 161 | /** 162 | * @return the fileName 163 | */ 164 | public String getFileName() { 165 | return fileName; 166 | } 167 | 168 | 169 | /** 170 | * @param fileName the fileName to set 171 | */ 172 | public void setFileName(String fileName) { 173 | this.fileName = fileName; 174 | } 175 | 176 | 177 | /** 178 | * @return the shareUsername 179 | */ 180 | public String getShareUsername() { 181 | return shareUsername; 182 | } 183 | 184 | 185 | /** 186 | * @param shareUsername the shareUsername to set 187 | */ 188 | public void setShareUsername(String shareUsername) { 189 | this.shareUsername = shareUsername; 190 | } 191 | 192 | 193 | /** 194 | * @return the sharePassword 195 | */ 196 | public String getSharePassword() { 197 | return sharePassword; 198 | } 199 | 200 | 201 | /** 202 | * @param sharePassword the sharePassword to set 203 | */ 204 | public void setSharePassword(String sharePassword) { 205 | this.sharePassword = sharePassword; 206 | } 207 | 208 | 209 | /** 210 | * @return the filePathName 211 | */ 212 | public String getFilePathName() { 213 | return filePathName; 214 | } 215 | 216 | 217 | /** 218 | * @param filePathName the filePathName to set 219 | */ 220 | public void setFilePathName(String filePathName) { 221 | this.filePathName = filePathName; 222 | } 223 | 224 | 225 | /** 226 | * @return the componentNames 227 | */ 228 | public List getComponentNames() { 229 | return componentNames; 230 | } 231 | 232 | 233 | /** 234 | * @param componentNames the componentNames to set 235 | */ 236 | public void setComponentNames(List componentNames) { 237 | this.componentNames = componentNames; 238 | } 239 | 240 | 241 | /** 242 | * @return the shutdownType 243 | */ 244 | public int getShutdownType() { 245 | return shutdownType; 246 | } 247 | 248 | 249 | /** 250 | * @param shutdownType the shutdownType to set 251 | */ 252 | public void setShutdownType(int shutdownType) { 253 | this.shutdownType = shutdownType; 254 | } 255 | 256 | 257 | /** 258 | * @return the randomFile 259 | */ 260 | public boolean isRandomFile() { 261 | return randomFile; 262 | } 263 | 264 | 265 | /** 266 | * @param randomFile the randomFile to set 267 | */ 268 | public void setRandomFile(boolean randomFile) { 269 | this.randomFile = randomFile; 270 | } 271 | 272 | 273 | /** 274 | * @return the sharePath 275 | */ 276 | public String getSharePath() { 277 | return sharePath; 278 | } 279 | 280 | 281 | /** 282 | * @param sharePath the sharePath to set 283 | */ 284 | public void setSharePath(String sharePath) { 285 | this.sharePath = sharePath; 286 | } 287 | } 288 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/model/ServerAndNetworkShareImageRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.model; 5 | 6 | import io.swagger.annotations.ApiModel; 7 | 8 | //import com.wordnik.swagger.annotations.ApiModel; 9 | 10 | import io.swagger.annotations.ApiModelProperty; 11 | 12 | /** 13 | * @author Muqeeth_Kowkab 14 | * 15 | */ 16 | 17 | @ApiModel(value = "ServerAndNetworkShareImageRequest", description = "Captures input request of server and network share details for image backup and restore. ") 18 | public class ServerAndNetworkShareImageRequest { 19 | 20 | @ApiModelProperty(value = "Server IP address.", dataType = "string", required = true) 21 | private String serverIP; 22 | 23 | @ApiModelProperty(value = "Server username.", dataType = "string", required = true) 24 | private String serverUsername; 25 | 26 | @ApiModelProperty(value = "Server password.", dataType = "string", required = true) 27 | private String serverPassword; 28 | 29 | @ApiModelProperty(value = "Type of share: NFS=0, CIFS=2", required = true) 30 | private int shareType; 31 | 32 | @ApiModelProperty(value = "The shared directory name on the server being exported. Not the location.", dataType = "string") 33 | private String shareName; 34 | 35 | @ApiModelProperty(value = "The IP address of the target export server", dataType = "string") 36 | private String shareAddress; 37 | 38 | @ApiModelProperty(value = "The target output file name.", dataType = "string") 39 | private String fileName; 40 | 41 | @ApiModelProperty(value = "Username of share server in the scenario of share type CIFS", dataType = "string") 42 | private String shareUsername; 43 | 44 | @ApiModelProperty(value = "Password of share server in the scenario of share type CIFS.", dataType = "string") 45 | private String sharePassword; 46 | 47 | @ApiModelProperty(value = "The name of the backup file. The parameter shall be required, if the ShareType parameter has value 0 (NFS), 2 (CIFS), or not specified.", dataType = "string") 48 | private String imageName; 49 | 50 | @ApiModelProperty(value = "The passPrase to extarct the image . The parameter shall be required, if the ShareType parameter has value 0 (NFS), or 2 (CIFS) or not specified.", dataType = "string") 51 | private String passPhrase; 52 | 53 | @ApiModelProperty(value = "Workgroup for the share.", dataType = "string") 54 | private String workgroup; 55 | 56 | @ApiModelProperty(value = "Start time for the job execution in format: yyyymmddhhmmss.The string TIME_NOW means immediate.", dataType = "string") 57 | private String scheduleStartTime; 58 | 59 | @ApiModelProperty(value = "End time for the job execution in format: yyyymmddhhmmss. :If this parameter is not NULL, then ScheduledStartTime parameter shall also be specified.", dataType = "string") 60 | private String untilTime; 61 | 62 | @ApiModelProperty(value = "Whether to preserve the VD (Virtual Disk) configuration.", dataType = "string") 63 | private String preserveVDConfig; 64 | 65 | 66 | /** 67 | * @return the serverIP 68 | */ 69 | public String getServerIP() { 70 | return serverIP; 71 | } 72 | 73 | 74 | /** 75 | * @param serverIP the serverIP to set 76 | */ 77 | public void setServerIP(String serverIP) { 78 | this.serverIP = serverIP; 79 | } 80 | 81 | 82 | /** 83 | * @return the serverUsername 84 | */ 85 | public String getServerUsername() { 86 | return serverUsername; 87 | } 88 | 89 | 90 | /** 91 | * @param serverUsername the serverUsername to set 92 | */ 93 | public void setServerUsername(String serverUsername) { 94 | this.serverUsername = serverUsername; 95 | } 96 | 97 | 98 | /** 99 | * @return the serverPassword 100 | */ 101 | public String getServerPassword() { 102 | return serverPassword; 103 | } 104 | 105 | 106 | /** 107 | * @param serverPassword the serverPassword to set 108 | */ 109 | public void setServerPassword(String serverPassword) { 110 | this.serverPassword = serverPassword; 111 | } 112 | 113 | 114 | /** 115 | * @return the shareType 116 | */ 117 | public int getShareType() { 118 | return shareType; 119 | } 120 | 121 | 122 | /** 123 | * @param shareType the shareType to set 124 | */ 125 | public void setShareType(int shareType) { 126 | this.shareType = shareType; 127 | } 128 | 129 | 130 | /** 131 | * @return the shareName 132 | */ 133 | public String getShareName() { 134 | return shareName; 135 | } 136 | 137 | 138 | /** 139 | * @param shareName the shareName to set 140 | */ 141 | public void setShareName(String shareName) { 142 | this.shareName = shareName; 143 | } 144 | 145 | 146 | /** 147 | * @return the shareAddress 148 | */ 149 | public String getShareAddress() { 150 | return shareAddress; 151 | } 152 | 153 | 154 | /** 155 | * @param shareAddress the shareAddress to set 156 | */ 157 | public void setShareAddress(String shareAddress) { 158 | this.shareAddress = shareAddress; 159 | } 160 | 161 | 162 | /** 163 | * @return the fileName 164 | */ 165 | public String getFileName() { 166 | return fileName; 167 | } 168 | 169 | 170 | /** 171 | * @param fileName the fileName to set 172 | */ 173 | public void setFileName(String fileName) { 174 | this.fileName = fileName; 175 | } 176 | 177 | 178 | /** 179 | * @return the shareUsername 180 | */ 181 | public String getShareUsername() { 182 | return shareUsername; 183 | } 184 | 185 | 186 | /** 187 | * @param shareUsername the shareUsername to set 188 | */ 189 | public void setShareUsername(String shareUsername) { 190 | this.shareUsername = shareUsername; 191 | } 192 | 193 | 194 | /** 195 | * @return the sharePassword 196 | */ 197 | public String getSharePassword() { 198 | return sharePassword; 199 | } 200 | 201 | 202 | /** 203 | * @param sharePassword the sharePassword to set 204 | */ 205 | public void setSharePassword(String sharePassword) { 206 | this.sharePassword = sharePassword; 207 | } 208 | 209 | 210 | /** 211 | * @return the filePathName 212 | */ 213 | public String getFilePathName() { 214 | return imageName; 215 | } 216 | 217 | 218 | /** 219 | * @param filePathName the filePathName to set 220 | */ 221 | public void setFilePathName(String filePathName) { 222 | this.imageName = filePathName; 223 | } 224 | 225 | 226 | public String getImageName() { 227 | return imageName; 228 | } 229 | 230 | 231 | public void setImageName(String imageName) { 232 | this.imageName = imageName; 233 | } 234 | 235 | 236 | public String getPassPhrase() { 237 | return passPhrase; 238 | } 239 | 240 | 241 | public void setPassPhrase(String passPhrase) { 242 | this.passPhrase = passPhrase; 243 | } 244 | 245 | 246 | public String getWorkgroup() { 247 | return workgroup; 248 | } 249 | 250 | 251 | public void setWorkgroup(String workgroup) { 252 | this.workgroup = workgroup; 253 | } 254 | 255 | 256 | public String getScheduleStartTime() { 257 | return scheduleStartTime; 258 | } 259 | 260 | 261 | public void setScheduleStartTime(String scheduleStartTime) { 262 | this.scheduleStartTime = scheduleStartTime; 263 | } 264 | 265 | 266 | public String getUntilTime() { 267 | return untilTime; 268 | } 269 | 270 | 271 | public void setUntilTime(String untilTime) { 272 | this.untilTime = untilTime; 273 | } 274 | 275 | 276 | public String getPreserveVDConfig() { 277 | return preserveVDConfig; 278 | } 279 | 280 | 281 | public void setPreserveVDConfig(String preserveVDConfig) { 282 | this.preserveVDConfig = preserveVDConfig; 283 | } 284 | 285 | } 286 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/utilities/ConfigurationUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.utilities; 5 | 6 | import java.io.File; 7 | import java.net.InetAddress; 8 | import java.text.ParseException; 9 | import java.text.SimpleDateFormat; 10 | import java.util.Date; 11 | 12 | import javax.xml.bind.JAXBContext; 13 | import javax.xml.bind.Unmarshaller; 14 | 15 | import org.apache.commons.lang3.RandomStringUtils; 16 | import org.apache.commons.lang3.StringUtils; 17 | import org.slf4j.Logger; 18 | import org.slf4j.LoggerFactory; 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | 21 | import com.dell.isg.smi.commons.model.credential.PasswordCredential; 22 | import com.dell.isg.smi.commons.model.fileshare.FileShare; 23 | import com.dell.isg.smi.commons.model.fileshare.FileShareTypeEnum; 24 | import com.dell.isg.smi.commons.utilities.fileshare.FileShareService; 25 | import com.dell.isg.smi.service.server.configuration.NfsYAMLConfiguration; 26 | import com.dell.isg.smi.service.server.configuration.model.ServerAndNetworkShareRequest; 27 | import com.dell.isg.smi.service.server.configuration.model.SystemConfiguration; 28 | 29 | /** 30 | * @author mkowkab 31 | * 32 | */ 33 | public class ConfigurationUtils { 34 | 35 | private static final Logger logger = LoggerFactory.getLogger(ConfigurationUtils.class.getName()); 36 | private static JAXBContext jc; 37 | 38 | 39 | /** 40 | * This Method unmarshal the XML file and returns the SystemConfiguration Object 41 | * 42 | * @param filePathName- The filePathName of the System Config file 43 | * @return SystemConfiguration object 44 | * @throws Exception 45 | */ 46 | public static SystemConfiguration getSystemConfiguration(String filePathName) throws Exception { 47 | SystemConfiguration systemConfig = null; 48 | try { 49 | jc = JAXBContext.newInstance(SystemConfiguration.class); 50 | Unmarshaller jaxbUnmarshaller = jc.createUnmarshaller(); 51 | File file = new File(filePathName); 52 | systemConfig = (SystemConfiguration) jaxbUnmarshaller.unmarshal(file); 53 | 54 | } catch (Exception e) { 55 | e.printStackTrace(); 56 | logger.error("Failed to getSystemConfiguration: " + e.getMessage()); 57 | throw e; 58 | } 59 | return systemConfig; 60 | } 61 | 62 | 63 | /** 64 | * This Method mount's the directory in the Docker container 65 | * 66 | * @param request 67 | * @param yamlConfig 68 | * @return 69 | * @throws Exception 70 | */ 71 | public static Boolean mount(ServerAndNetworkShareRequest request, NfsYAMLConfiguration yamlConfig) throws Exception { 72 | Boolean result = true; 73 | try { 74 | if (null != request && null != yamlConfig && !fileExist("/shares/remote/" + request.getSharePath())) { 75 | logger.info("Mount doesn't exist. Creating a mount for " + request.getFilePathName()); 76 | FileShareService fileShareService = new FileShareService(); 77 | FileShare fileShare = new FileShare(); 78 | fileShare.setAddress(request.getShareAddress()); 79 | fileShare.setName(request.getSharePath()); // SharePath will be used as mount location folder name 80 | fileShare.setPath(request.getShareName()); // this is the path of remote share 81 | int shareType = request.getShareType(); 82 | 83 | FileShareTypeEnum type = null; 84 | if (shareType==0) { 85 | type = FileShareTypeEnum.NFS; 86 | } else if (shareType==2) { 87 | type = FileShareTypeEnum.CIFS; 88 | PasswordCredential passwordCreds = new PasswordCredential(); 89 | passwordCreds.setUsername(request.getShareUsername()); 90 | passwordCreds.setPassword(request.getSharePassword()); 91 | fileShare.setPasswordCredential(passwordCreds); 92 | } 93 | 94 | fileShare.setType(type); 95 | fileShare.setScriptName(yamlConfig.getScript_name()); 96 | fileShare.setScriptDirectory(yamlConfig.getScript_directory()); 97 | result = fileShareService.mount(fileShare); 98 | logger.info("ScriptFileName: " + yamlConfig.getScript_name()); 99 | } 100 | 101 | } catch (Exception e) { 102 | e.printStackTrace(); 103 | logger.error("Failed to mountNFS: " + e.getMessage()); 104 | result = false; 105 | } 106 | logger.info("ConfigurationUtils: mountNFS:" + result); 107 | return result; 108 | 109 | } 110 | 111 | 112 | /** 113 | * This method generates the unique filename 114 | * 115 | * @return RandomAlphanumeric String 116 | */ 117 | public static String getUniqueFileName() { 118 | String fileName = RandomStringUtils.randomAlphanumeric(10); 119 | return fileName; 120 | } 121 | 122 | 123 | /** 124 | * This Method validates the IP address 125 | * 126 | * @param ipAddress the IP to be validated 127 | * @return true if reachable otherwise false 128 | */ 129 | public static boolean validateIPAddress(String ipAddress) { 130 | try { 131 | if (StringUtils.isNotBlank(ipAddress)) { 132 | return InetAddress.getByName(ipAddress).isReachable(2000); 133 | } else { 134 | return false; 135 | } 136 | } catch (Exception e) { 137 | return false; 138 | } 139 | } 140 | 141 | 142 | public static boolean fileExist(String filePathName) { 143 | File file = new File(filePathName); 144 | return file.exists(); 145 | } 146 | 147 | 148 | public static void removeRandomFile(ServerAndNetworkShareRequest request, NfsYAMLConfiguration yamlConfig) { 149 | try { 150 | if (null != request && request.isRandomFile()) { 151 | String filePathName = request.getFilePathName(); 152 | if (StringUtils.isNotBlank(filePathName) && fileExist(filePathName)) { 153 | File file = new File(filePathName); 154 | file.delete(); 155 | logger.info("Removed the random file " + filePathName); 156 | } 157 | } 158 | if (null != request && null != yamlConfig) { 159 | String shareName = request.getSharePath(); 160 | if (StringUtils.isNotBlank(shareName)) { 161 | FileShareService fileShareService = new FileShareService(); 162 | FileShare fileShare = new FileShare(); 163 | fileShare.setName(shareName); 164 | String scriptName = yamlConfig.getScript_name(); 165 | String scriptDirectory = yamlConfig.getScript_directory(); 166 | fileShare.setScriptName(scriptName); 167 | fileShare.setScriptDirectory(scriptDirectory); 168 | Boolean unmounted = fileShareService.unmount(fileShare); 169 | logger.info("unmounted " + shareName + " status: " + unmounted); 170 | } 171 | } 172 | 173 | } catch (Exception e) { 174 | logger.error("Could not remove the random file/unmount failed."); 175 | } 176 | 177 | } 178 | 179 | 180 | public static boolean validateTime(String scheduledStartTime) { 181 | boolean isValid = true; 182 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); 183 | dateFormat.setLenient(false); 184 | try { 185 | Date date = dateFormat.parse(scheduledStartTime); 186 | logger.info("validateTime: date: " + date); 187 | } catch (ParseException e) { 188 | logger.error("exception in validateTime " + e.getMessage()); 189 | return false; 190 | 191 | } 192 | return isValid; 193 | } 194 | 195 | 196 | public static boolean validateEndTimeAfterStartTime(String startTime, String endTime) { 197 | boolean isValid = false; 198 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); 199 | dateFormat.setLenient(false); 200 | try { 201 | Date startDate = dateFormat.parse(startTime); 202 | Date endDate = dateFormat.parse(endTime); 203 | if (endDate.after(startDate)) { 204 | isValid = true; 205 | } 206 | } catch (ParseException e) { 207 | logger.error("exception in validateEndTimeAfterStartTime " + e.getMessage()); 208 | } 209 | return isValid; 210 | } 211 | } 212 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/model/SystemConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | // 5 | // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 6 | // See http://java.sun.com/xml/jaxb 7 | // Any modifications to this file will be lost upon recompilation of the source schema. 8 | // Generated on: 2016.11.02 at 04:49:32 PM CDT 9 | // 10 | 11 | package com.dell.isg.smi.service.server.configuration.model; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | import javax.xml.bind.annotation.XmlAccessType; 16 | import javax.xml.bind.annotation.XmlAccessorType; 17 | import javax.xml.bind.annotation.XmlAttribute; 18 | import javax.xml.bind.annotation.XmlElement; 19 | import javax.xml.bind.annotation.XmlRootElement; 20 | import javax.xml.bind.annotation.XmlType; 21 | 22 | /** 23 | *

24 | * Java class for anonymous complex type. 25 | * 26 | *

27 | * The following schema fragment specifies the expected content contained within this class. 28 | * 29 | *

 30 |  * <complexType>
 31 |  *   <complexContent>
 32 |  *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 33 |  *       <sequence>
 34 |  *         <element name="Component" maxOccurs="unbounded">
 35 |  *           <complexType>
 36 |  *             <complexContent>
 37 |  *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 38 |  *                 <sequence>
 39 |  *                   <element name="Attribute" maxOccurs="unbounded">
 40 |  *                     <complexType>
 41 |  *                       <simpleContent>
 42 |  *                         <extension base="<http://www.w3.org/2001/XMLSchema>string">
 43 |  *                           <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
 44 |  *                         </extension>
 45 |  *                       </simpleContent>
 46 |  *                     </complexType>
 47 |  *                   </element>
 48 |  *                   <element name="Component" maxOccurs="unbounded" minOccurs="0">
 49 |  *                     <complexType>
 50 |  *                       <complexContent>
 51 |  *                         <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 52 |  *                           <sequence>
 53 |  *                             <element name="Component" maxOccurs="unbounded" minOccurs="0">
 54 |  *                               <complexType>
 55 |  *                                 <complexContent>
 56 |  *                                   <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 57 |  *                                     <sequence>
 58 |  *                                       <element name="Attribute" maxOccurs="unbounded">
 59 |  *                                         <complexType>
 60 |  *                                           <simpleContent>
 61 |  *                                             <extension base="<http://www.w3.org/2001/XMLSchema>string">
 62 |  *                                               <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
 63 |  *                                             </extension>
 64 |  *                                           </simpleContent>
 65 |  *                                         </complexType>
 66 |  *                                       </element>
 67 |  *                                     </sequence>
 68 |  *                                     <attribute name="FQDD" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
 69 |  *                                   </restriction>
 70 |  *                                 </complexContent>
 71 |  *                               </complexType>
 72 |  *                             </element>
 73 |  *                             <element name="Attribute" maxOccurs="unbounded" minOccurs="0">
 74 |  *                               <complexType>
 75 |  *                                 <simpleContent>
 76 |  *                                   <extension base="<http://www.w3.org/2001/XMLSchema>string">
 77 |  *                                     <attribute name="Name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
 78 |  *                                   </extension>
 79 |  *                                 </simpleContent>
 80 |  *                               </complexType>
 81 |  *                             </element>
 82 |  *                           </sequence>
 83 |  *                           <attribute name="FQDD" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
 84 |  *                         </restriction>
 85 |  *                       </complexContent>
 86 |  *                     </complexType>
 87 |  *                   </element>
 88 |  *                 </sequence>
 89 |  *                 <attribute name="FQDD" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
 90 |  *               </restriction>
 91 |  *             </complexContent>
 92 |  *           </complexType>
 93 |  *         </element>
 94 |  *       </sequence>
 95 |  *       <attribute name="Model" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
 96 |  *       <attribute name="ServiceTag" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
 97 |  *       <attribute name="TimeStamp" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
 98 |  *     </restriction>
 99 |  *   </complexContent>
100 |  * </complexType>
101 |  * 
102 | * 103 | * 104 | */ 105 | @XmlAccessorType(XmlAccessType.FIELD) 106 | @XmlType(name = "", propOrder = { "serverComponents" }) 107 | @XmlRootElement(name = "SystemConfiguration") 108 | public class SystemConfiguration { 109 | 110 | @XmlElement(name = "Component", required = true) 111 | protected List serverComponents; 112 | @XmlAttribute(name = "Model", required = true) 113 | protected String model; 114 | @XmlAttribute(name = "ServiceTag", required = true) 115 | protected String serviceTag; 116 | @XmlAttribute(name = "TimeStamp", required = true) 117 | protected String timeStamp; 118 | 119 | 120 | /** 121 | * Gets the value of the component property. 122 | * 123 | *

124 | * This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make to the returned list will be present inside the JAXB object. 125 | * This is why there is not a set method for the component property. 126 | * 127 | *

128 | * For example, to add a new item, do as follows: 129 | * 130 | *

131 |      * getComponent().add(newItem);
132 |      * 
133 | * 134 | * 135 | *

136 | * Objects of the following type(s) are allowed in the list {@link SystemConfiguration.Component } 137 | * 138 | * 139 | */ 140 | // public List getComponent() { 141 | // if (component == null) { 142 | // component = new ArrayList(); 143 | // } 144 | // return this.component; 145 | // } 146 | 147 | /** 148 | * @return the serverComponents 149 | */ 150 | public List getServerComponents() { 151 | if (serverComponents == null) { 152 | serverComponents = new ArrayList(); 153 | } 154 | return this.serverComponents; 155 | } 156 | 157 | 158 | /** 159 | * @param serverComponents the serverComponents to set 160 | */ 161 | public void setServerComponents(List serverComponents) { 162 | this.serverComponents = serverComponents; 163 | } 164 | 165 | 166 | /** 167 | * Gets the value of the model property. 168 | * 169 | * @return possible object is {@link String } 170 | * 171 | */ 172 | public String getModel() { 173 | return model; 174 | } 175 | 176 | 177 | /** 178 | * Sets the value of the model property. 179 | * 180 | * @param value allowed object is {@link String } 181 | * 182 | */ 183 | public void setModel(String value) { 184 | this.model = value; 185 | } 186 | 187 | 188 | /** 189 | * Gets the value of the serviceTag property. 190 | * 191 | * @return possible object is {@link String } 192 | * 193 | */ 194 | public String getServiceTag() { 195 | return serviceTag; 196 | } 197 | 198 | 199 | /** 200 | * Sets the value of the serviceTag property. 201 | * 202 | * @param value allowed object is {@link String } 203 | * 204 | */ 205 | public void setServiceTag(String value) { 206 | this.serviceTag = value; 207 | } 208 | 209 | 210 | /** 211 | * Gets the value of the timeStamp property. 212 | * 213 | * @return possible object is {@link String } 214 | * 215 | */ 216 | public String getTimeStamp() { 217 | return timeStamp; 218 | } 219 | 220 | 221 | /** 222 | * Sets the value of the timeStamp property. 223 | * 224 | * @param value allowed object is {@link String } 225 | * 226 | */ 227 | public void setTimeStamp(String value) { 228 | this.timeStamp = value; 229 | } 230 | 231 | } 232 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /src/test/java/com/dell/isg/smi/service/server/configuration/manager/ConfigurationManagerImplTest.java: -------------------------------------------------------------------------------- 1 | package com.dell.isg.smi.service.server.configuration.manager; 2 | 3 | import com.dell.isg.smi.service.server.configuration.model.Attribute; 4 | import com.dell.isg.smi.service.server.configuration.model.ComponentList; 5 | import com.dell.isg.smi.service.server.configuration.model.NestedComponent; 6 | import com.dell.isg.smi.service.server.configuration.model.ServerAndNetworkShareRequest; 7 | import com.dell.isg.smi.service.server.configuration.model.ServerComponent; 8 | import com.dell.isg.smi.service.server.configuration.model.SubComponent; 9 | import com.dell.isg.smi.service.server.configuration.model.SystemConfiguration; 10 | import org.apache.catalina.Server; 11 | import org.apache.commons.collections4.CollectionUtils; 12 | import org.eclipse.persistence.jaxb.JAXBContextFactory; 13 | import org.junit.Before; 14 | import org.junit.Test; 15 | import org.w3c.dom.Document; 16 | import org.w3c.dom.Node; 17 | 18 | import javax.xml.bind.Binder; 19 | import javax.xml.bind.JAXBContext; 20 | import javax.xml.bind.Marshaller; 21 | import javax.xml.parsers.DocumentBuilder; 22 | import javax.xml.parsers.DocumentBuilderFactory; 23 | import java.io.File; 24 | import java.net.URL; 25 | import java.nio.file.Files; 26 | import java.nio.file.Path; 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | 30 | import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; 31 | import static org.junit.Assert.assertNotNull; 32 | import static org.junit.Assert.assertTrue; 33 | import static org.junit.Assert.fail; 34 | 35 | public class ConfigurationManagerImplTest { 36 | private IConfigurationManager configManager; 37 | 38 | @Before 39 | public void setup() { 40 | configManager = new ConfigurationManagerImpl(); 41 | } 42 | 43 | @Test 44 | public void testForceUpdateComponents() throws Exception { 45 | URL origFile = Thread.currentThread().getContextClassLoader().getResource("exported-scp-1.xml"); 46 | assertNotNull("Failed to load exported-scp-1.xml", origFile); 47 | 48 | Path tempFile = Files.createTempFile("ConfigurationManagerImplTest", "testIt"); 49 | try { 50 | Files.copy(new File(origFile.getPath()).toPath(), tempFile, REPLACE_EXISTING); 51 | 52 | ComponentList request = new ComponentList(); 53 | ServerAndNetworkShareRequest shareRequest = new ServerAndNetworkShareRequest(); 54 | shareRequest.setFilePathName(tempFile.toString()); 55 | request.setServerAndNetworkShareRequest(shareRequest); 56 | List serverComponents = new ArrayList<>(); 57 | 58 | ServerComponent component = new ServerComponent(); 59 | component.setFQDD("BIOS.Setup.1-1"); 60 | component.setAttributes(new ArrayList<>()); 61 | Attribute attr = new Attribute(); 62 | attr.setName("MemTest"); 63 | attr.setValue("Enabled"); 64 | component.getAttributes().add(attr); 65 | attr = new Attribute(); 66 | attr.setName("SecureBoot"); 67 | attr.setValue("Enabled"); 68 | component.getAttributes().add(attr); 69 | serverComponents.add(component); 70 | 71 | component = new ServerComponent(); 72 | component.setFQDD("RAID.Slot.1-1"); 73 | component.setSubComponents(new ArrayList<>()); 74 | 75 | SubComponent subComponent = new SubComponent(); 76 | subComponent.setAttributes(new ArrayList<>()); 77 | subComponent.setFQDD("Enclosure.Internal.0-0:RAID.Slot.1-1"); 78 | subComponent.setNestedComponents(new ArrayList<>()); 79 | NestedComponent nestedComponent = new NestedComponent(); 80 | nestedComponent.setFQDD("Disk.Bay.0:Enclosure.Internal.0-0:RAID.Slot.1-1"); 81 | nestedComponent.setAttributes(new ArrayList<>()); 82 | attr = new Attribute(); 83 | attr.setName("RAIDHotSpareStatus"); 84 | attr.setValue("Yes"); 85 | nestedComponent.getAttributes().add(attr); 86 | attr = new Attribute(); 87 | attr.setName("RAIDPDState"); 88 | attr.setValue("Online"); 89 | nestedComponent.getAttributes().add(attr); 90 | subComponent.getNestedComponents().add(nestedComponent); 91 | component.getSubComponents().add(subComponent); 92 | 93 | subComponent = new SubComponent(); 94 | subComponent.setAttributes(new ArrayList<>()); 95 | subComponent.setFQDD("Disk.Virtual.0:RAID.Slot.1-1"); 96 | attr = new Attribute(); 97 | attr.setName("T10PIStatus"); 98 | attr.setValue("Enabled"); 99 | subComponent.getAttributes().add(attr); 100 | attr = new Attribute(); 101 | attr.setName("DiskCachePolicy"); 102 | attr.setValue("Enabled"); 103 | subComponent.getAttributes().add(attr); 104 | component.getSubComponents().add(subComponent); 105 | serverComponents.add(component); 106 | request.setServerComponents(serverComponents); 107 | 108 | List updatedComponents = configManager.updateComponents(request, true); 109 | 110 | assertTrue(updatedComponents.size() == 2); 111 | for (ServerComponent serverComponent : updatedComponents) { 112 | if (CollectionUtils.isNotEmpty(serverComponent.getAttributes())) 113 | { 114 | assertTrue(serverComponent.getAttributes().size() == 2); 115 | } 116 | if (CollectionUtils.isNotEmpty(serverComponent.getSubComponents())) { 117 | for (SubComponent sub : serverComponent.getSubComponents()) { 118 | if (CollectionUtils.isNotEmpty(sub.getAttributes())) 119 | { 120 | assertTrue(sub.getAttributes().size() == 2); 121 | } 122 | if (CollectionUtils.isNotEmpty(sub.getNestedComponents())) { 123 | for (NestedComponent nested : sub.getNestedComponents()) { 124 | if (CollectionUtils.isNotEmpty(nested.getAttributes())) 125 | { 126 | assertTrue(nested.getAttributes().size() == 2); 127 | } 128 | } 129 | } 130 | } 131 | } 132 | } 133 | 134 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 135 | DocumentBuilder db = dbf.newDocumentBuilder(); 136 | 137 | Document document = db.parse(tempFile.toFile()); 138 | JAXBContext jaxbContext = JAXBContextFactory.createContext(new Class[] { SystemConfiguration.class }, 139 | null); 140 | 141 | Binder binder = jaxbContext.createBinder(); 142 | binder.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); 143 | binder.setProperty(Marshaller.JAXB_FRAGMENT, true); 144 | 145 | SystemConfiguration systemConfig = (SystemConfiguration) binder.unmarshal(document); 146 | assertNotNull(systemConfig); 147 | for (ServerComponent serverComponent : systemConfig.getServerComponents()) { 148 | if (serverComponent.getFQDD().equals("BIOS.Setup.1-1")) { 149 | for (Attribute attribute : serverComponent.getAttributes()) { 150 | switch (attribute.getName()) { 151 | case "MemTest": 152 | assertTrue(attribute.getValue().equals("Enabled")); 153 | break; 154 | case "SecureBoot": 155 | assertTrue(attribute.getValue().equals("Enabled")); 156 | break; 157 | default: 158 | break; 159 | } 160 | } 161 | } else if (serverComponent.getFQDD().equals("RAID.Slot.1-1")) { 162 | for (SubComponent sub : serverComponent.getSubComponents()) 163 | { 164 | if (sub.getFQDD().equals("Disk.Virtual.0:RAID.Slot.1-1")) 165 | { 166 | for (Attribute attribute : sub.getAttributes()) { 167 | switch (attribute.getName()) 168 | { 169 | case "T10PIStatus": 170 | assertTrue(attribute.getValue().equals("Enabled")); 171 | break; 172 | case "DiskCachePolicy": 173 | assertTrue(attribute.getValue().equals("Enabled")); 174 | break; 175 | } 176 | } 177 | } else if (sub.getFQDD().equals("Enclosure.Internal.0-0:RAID.Slot.1-1")) 178 | { 179 | for (NestedComponent nested : subComponent.getNestedComponents()) 180 | { 181 | if (nested.getFQDD().equals("Disk.Bay.0:Enclosure.Internal.0-0:RAID.Slot.1-1")) 182 | { 183 | for (Attribute attribute : nestedComponent.getAttributes()) 184 | { 185 | if (attribute.getName().equals("RAIDHotSpareStatus")) 186 | { 187 | assertTrue(attribute.getValue().equals("Yes")); 188 | } 189 | else if (attribute.getName().equals(("RAIDPDState"))) 190 | { 191 | assertTrue(attribute.getValue().equals("Online")); 192 | } 193 | } 194 | } 195 | } 196 | } 197 | } 198 | } 199 | } 200 | 201 | } finally { 202 | Files.deleteIfExists(tempFile); 203 | } 204 | } 205 | 206 | @Test 207 | public void testUpdateComponents() throws Exception { 208 | URL origFile = Thread.currentThread().getContextClassLoader().getResource("exported-scp-1.xml"); 209 | assertNotNull("Failed to load exported-scp-1.xml", origFile); 210 | 211 | Path tempFile = Files.createTempFile("ConfigurationManagerImplTest", "testIt"); 212 | try { 213 | Files.copy(new File(origFile.getPath()).toPath(), tempFile, REPLACE_EXISTING); 214 | 215 | ComponentList request = new ComponentList(); 216 | ServerAndNetworkShareRequest shareRequest = new ServerAndNetworkShareRequest(); 217 | shareRequest.setFilePathName(tempFile.toString()); 218 | request.setServerAndNetworkShareRequest(shareRequest); 219 | List serverComponents = new ArrayList<>(); 220 | 221 | ServerComponent component = new ServerComponent(); 222 | component.setFQDD("BIOS.Setup.1-1"); 223 | component.setAttributes(new ArrayList<>()); 224 | Attribute attr = new Attribute(); 225 | attr.setName("MemTest"); 226 | attr.setValue("Enabled"); 227 | component.getAttributes().add(attr); 228 | attr = new Attribute(); 229 | attr.setName("SecureBoot"); 230 | attr.setValue("Enabled"); 231 | component.getAttributes().add(attr); 232 | serverComponents.add(component); 233 | 234 | component = new ServerComponent(); 235 | component.setFQDD("RAID.Slot.1-1"); 236 | component.setSubComponents(new ArrayList<>()); 237 | 238 | SubComponent subComponent = new SubComponent(); 239 | subComponent.setAttributes(new ArrayList<>()); 240 | subComponent.setFQDD("Enclosure.Internal.0-0:RAID.Slot.1-1"); 241 | subComponent.setNestedComponents(new ArrayList<>()); 242 | NestedComponent nestedComponent = new NestedComponent(); 243 | nestedComponent.setFQDD("Disk.Bay.0:Enclosure.Internal.0-0:RAID.Slot.1-1"); 244 | nestedComponent.setAttributes(new ArrayList<>()); 245 | attr = new Attribute(); 246 | attr.setName("RAIDHotSpareStatus"); 247 | attr.setValue("Yes"); 248 | nestedComponent.getAttributes().add(attr); 249 | attr = new Attribute(); 250 | attr.setName("RAIDPDState"); 251 | attr.setValue("Online"); 252 | nestedComponent.getAttributes().add(attr); 253 | subComponent.getNestedComponents().add(nestedComponent); 254 | component.getSubComponents().add(subComponent); 255 | 256 | subComponent = new SubComponent(); 257 | subComponent.setAttributes(new ArrayList<>()); 258 | subComponent.setFQDD("Disk.Virtual.0:RAID.Slot.1-1"); 259 | attr = new Attribute(); 260 | attr.setName("T10PIStatus"); 261 | attr.setValue("Enabled"); 262 | subComponent.getAttributes().add(attr); 263 | attr = new Attribute(); 264 | attr.setName("DiskCachePolicy"); 265 | attr.setValue("Enabled"); 266 | subComponent.getAttributes().add(attr); 267 | component.getSubComponents().add(subComponent); 268 | serverComponents.add(component); 269 | request.setServerComponents(serverComponents); 270 | 271 | List updatedComponents = configManager.updateComponents(request, false); 272 | 273 | assertTrue(updatedComponents.size() == 2); 274 | for (ServerComponent serverComponent : updatedComponents) { 275 | if (CollectionUtils.isNotEmpty(serverComponent.getAttributes())) 276 | { 277 | assertTrue(serverComponent.getAttributes().size() == 1); 278 | } 279 | if (CollectionUtils.isNotEmpty(serverComponent.getSubComponents())) { 280 | for (SubComponent sub : serverComponent.getSubComponents()) { 281 | if (CollectionUtils.isNotEmpty(sub.getAttributes())) 282 | { 283 | assertTrue(sub.getAttributes().size() == 1); 284 | } 285 | if (CollectionUtils.isNotEmpty(sub.getNestedComponents())) { 286 | for (NestedComponent nested : sub.getNestedComponents()) { 287 | if (CollectionUtils.isNotEmpty(nested.getAttributes())) 288 | { 289 | assertTrue(nested.getAttributes().size() == 1); 290 | } 291 | } 292 | } 293 | } 294 | } 295 | } 296 | 297 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 298 | DocumentBuilder db = dbf.newDocumentBuilder(); 299 | 300 | Document document = db.parse(tempFile.toFile()); 301 | JAXBContext jaxbContext = JAXBContextFactory.createContext(new Class[] { SystemConfiguration.class }, 302 | null); 303 | 304 | Binder binder = jaxbContext.createBinder(); 305 | binder.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); 306 | binder.setProperty(Marshaller.JAXB_FRAGMENT, true); 307 | 308 | SystemConfiguration systemConfig = (SystemConfiguration) binder.unmarshal(document); 309 | assertNotNull(systemConfig); 310 | for (ServerComponent serverComponent : systemConfig.getServerComponents()) { 311 | if (serverComponent.getFQDD().equals("BIOS.Setup.1-1")) { 312 | for (Attribute attribute : serverComponent.getAttributes()) { 313 | switch (attribute.getName()) { 314 | case "MemTest": 315 | assertTrue(attribute.getValue().equals("Enabled")); 316 | break; 317 | case "SecureBoot": 318 | fail("Attribute SecureBoot should be commented out!"); 319 | break; 320 | default: 321 | break; 322 | } 323 | } 324 | } else if (serverComponent.getFQDD().equals("RAID.Slot.1-1")) { 325 | for (SubComponent sub : serverComponent.getSubComponents()) 326 | { 327 | if (sub.getFQDD().equals("Disk.Virtual.0:RAID.Slot.1-1")) 328 | { 329 | for (Attribute attribute : sub.getAttributes()) { 330 | switch (attribute.getName()) 331 | { 332 | case "T10PIStatus": 333 | fail("Attribute T10PIStatus should be commented out!"); 334 | break; 335 | case "DiskCachePolicy": 336 | assertTrue(attribute.getValue().equals("Enabled")); 337 | break; 338 | } 339 | } 340 | } else if (sub.getFQDD().equals("Enclosure.Internal.0-0:RAID.Slot.1-1")) 341 | { 342 | for (NestedComponent nested : subComponent.getNestedComponents()) 343 | { 344 | if (nested.getFQDD().equals("Disk.Bay.0:Enclosure.Internal.0-0:RAID.Slot.1-1")) 345 | { 346 | for (Attribute attribute : nestedComponent.getAttributes()) 347 | { 348 | switch (attribute.getName()) 349 | { 350 | case "RAIDHotSpareStatus": 351 | fail("Attribute RAIDHotSpareStatus should be commented out!"); 352 | break; 353 | case "RAIDPDState": 354 | assertTrue(attribute.getValue().equals("Online")); 355 | break; 356 | } 357 | } 358 | } 359 | } 360 | } 361 | } 362 | } 363 | } 364 | 365 | } finally { 366 | Files.deleteIfExists(tempFile); 367 | } 368 | } 369 | 370 | 371 | } 372 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/service/server/configuration/manager/ConfigurationManagerImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2017 DELL Inc. or its subsidiaries. All Rights Reserved. 3 | */ 4 | package com.dell.isg.smi.service.server.configuration.manager; 5 | 6 | import com.dell.isg.smi.adapter.server.config.ConfigEnum.EXPORT_MODE; 7 | import com.dell.isg.smi.adapter.server.config.ConfigEnum.SHARE_TYPES; 8 | import com.dell.isg.smi.adapter.server.config.IConfigAdapter; 9 | import com.dell.isg.smi.adapter.server.inventory.IInventoryAdapter; 10 | import com.dell.isg.smi.adapter.server.model.NetworkShare; 11 | import com.dell.isg.smi.adapter.server.model.WsmanCredentials; 12 | import com.dell.isg.smi.commons.model.common.Credential; 13 | import com.dell.isg.smi.service.server.configuration.NfsYAMLConfiguration; 14 | import com.dell.isg.smi.service.server.configuration.model.Attribute; 15 | import com.dell.isg.smi.service.server.configuration.model.BiosSetupRequest; 16 | import com.dell.isg.smi.service.server.configuration.model.ComponentList; 17 | import com.dell.isg.smi.service.server.configuration.model.ComponentPredicate; 18 | import com.dell.isg.smi.service.server.configuration.model.ConfigureBiosResult; 19 | import com.dell.isg.smi.service.server.configuration.model.DCIM_BIOSEnumeration; 20 | import com.dell.isg.smi.service.server.configuration.model.DCIM_BootSourceSetting; 21 | import com.dell.isg.smi.service.server.configuration.model.NestedComponent; 22 | import com.dell.isg.smi.service.server.configuration.model.ServerAndNetworkShareImageRequest; 23 | import com.dell.isg.smi.service.server.configuration.model.ServerAndNetworkShareRequest; 24 | import com.dell.isg.smi.service.server.configuration.model.ServerComponent; 25 | import com.dell.isg.smi.service.server.configuration.model.ServerRequest; 26 | import com.dell.isg.smi.service.server.configuration.model.SubComponent; 27 | import com.dell.isg.smi.service.server.configuration.model.SystemBiosSettings; 28 | import com.dell.isg.smi.service.server.configuration.model.SystemConfiguration; 29 | import com.dell.isg.smi.service.server.configuration.model.SystemEraseRequest; 30 | import com.dell.isg.smi.service.server.configuration.utilities.ConfigurationUtils; 31 | import com.dell.isg.smi.wsman.model.XmlConfig; 32 | import com.jayway.jsonpath.Configuration; 33 | import com.jayway.jsonpath.JsonPath; 34 | import com.jayway.jsonpath.TypeRef; 35 | import org.apache.commons.collections4.CollectionUtils; 36 | import org.apache.commons.lang3.StringUtils; 37 | import org.slf4j.Logger; 38 | import org.slf4j.LoggerFactory; 39 | import org.springframework.beans.factory.annotation.Autowired; 40 | import org.springframework.context.support.ResourceBundleMessageSource; 41 | import org.springframework.stereotype.Component; 42 | import org.w3c.dom.Document; 43 | import org.w3c.dom.Element; 44 | import org.w3c.dom.Node; 45 | 46 | import javax.xml.parsers.DocumentBuilder; 47 | import javax.xml.parsers.DocumentBuilderFactory; 48 | import javax.xml.transform.Transformer; 49 | import javax.xml.transform.TransformerFactory; 50 | import javax.xml.transform.dom.DOMSource; 51 | import javax.xml.transform.stream.StreamResult; 52 | import javax.xml.xpath.XPath; 53 | import javax.xml.xpath.XPathConstants; 54 | import javax.xml.xpath.XPathExpressionException; 55 | import javax.xml.xpath.XPathFactory; 56 | import java.io.File; 57 | import java.util.ArrayList; 58 | import java.util.HashMap; 59 | import java.util.LinkedHashSet; 60 | import java.util.LinkedList; 61 | import java.util.List; 62 | import java.util.Locale; 63 | import java.util.Map; 64 | import java.util.Set; 65 | 66 | /** 67 | * @author Muqeeth_Kowkab 68 | * 69 | */ 70 | 71 | @Component 72 | public class ConfigurationManagerImpl implements IConfigurationManager { 73 | 74 | private static final String MESSAGE = "Message"; 75 | 76 | private static final Logger logger = LoggerFactory.getLogger(ConfigurationManagerImpl.class.getName()); 77 | 78 | private static final int TIME_DELAY_MILLISECONDS = 30000; 79 | 80 | private static final int POLL_JOB_RETRY = 12; 81 | 82 | private static final String BIOS_SETUP_1_1 = "BIOS.Setup.1-1"; 83 | 84 | private static final String COMPLETED_WITH_NO_ERROR = "Completed with no error"; 85 | 86 | private static final String THE_COMMAND_WAS_SUCCESSFUL = "The command was successful"; 87 | 88 | private static final String BOOTSOURCE_BCV = "BCV"; 89 | 90 | private static final String BOOTSOURCE_IPL = "IPL"; 91 | 92 | private static final String JOB_ID = "JobId"; 93 | 94 | @Autowired 95 | NfsYAMLConfiguration yamlConfig; 96 | 97 | @Autowired 98 | IConfigAdapter configAdapter; 99 | 100 | @Autowired 101 | IInventoryAdapter inventoryAdapter; 102 | 103 | @Autowired 104 | Configuration jsonPathConfiguration; 105 | 106 | @Autowired 107 | ComponentPredicate componentPredicate; 108 | 109 | @Autowired 110 | ResourceBundleMessageSource messageSource; 111 | 112 | 113 | 114 | public ConfigurationManagerImpl() { 115 | } 116 | 117 | @Override 118 | public XmlConfig importConfiguration(ServerAndNetworkShareRequest request) throws Exception { 119 | 120 | WsmanCredentials wsmanCredentials = new WsmanCredentials(request.getServerIP(), request.getServerUsername(), 121 | request.getServerPassword()); 122 | 123 | return configAdapter.applyServerConfig(wsmanCredentials, getNetworkShare(request), request.getShutdownType()); 124 | } 125 | 126 | @Override 127 | public Object previewConfiguration(ServerAndNetworkShareRequest request) throws Exception { 128 | WsmanCredentials wsmanCredentials = new WsmanCredentials(request.getServerIP(), request.getServerUsername(), 129 | request.getServerPassword()); 130 | 131 | XmlConfig config = configAdapter.previewImportServerConfig(wsmanCredentials, getNetworkShare(request)); 132 | Object result = configAdapter.previewConfigResults(wsmanCredentials, config.getJobID()); 133 | 134 | return result; 135 | } 136 | 137 | @Override 138 | public XmlConfig exportConfiguration(ServerAndNetworkShareRequest request, String exportMode) throws Exception { 139 | 140 | WsmanCredentials wsmanCredentials = new WsmanCredentials(request.getServerIP(), request.getServerUsername(), 141 | request.getServerPassword()); 142 | 143 | String components = StringUtils.join(request.getComponentNames(), ","); 144 | 145 | return configAdapter.exportServerConfig(wsmanCredentials, getNetworkShare(request), components, exportMode); 146 | } 147 | 148 | @Override 149 | public XmlConfig factoryConfiguration(ServerAndNetworkShareRequest request) throws Exception { 150 | WsmanCredentials wsmanCredentials = new WsmanCredentials(request.getServerIP(), request.getServerUsername(), 151 | request.getServerPassword()); 152 | 153 | XmlConfig config = configAdapter.exportFactorySetting(wsmanCredentials, getNetworkShare(request)); 154 | return config; 155 | } 156 | 157 | @Override 158 | public XmlConfig exportInventory(ServerAndNetworkShareRequest request) throws Exception { 159 | WsmanCredentials wsmanCredentials = new WsmanCredentials(request.getServerIP(), request.getServerUsername(), 160 | request.getServerPassword()); 161 | 162 | XmlConfig config = configAdapter.exportHardwareInventory(wsmanCredentials, getNetworkShare(request)); 163 | return config; 164 | } 165 | 166 | @Override 167 | public List getComponents(ServerAndNetworkShareRequest request) throws Exception { 168 | List components = extractComponents(request); 169 | return components; 170 | } 171 | 172 | @Override 173 | public XmlConfig wipeLifeController(Credential request) throws Exception { 174 | WsmanCredentials wsmanCredentials = new WsmanCredentials(request.getAddress(), request.getUserName(), 175 | request.getPassword()); 176 | XmlConfig config = configAdapter.wipeLifeController(wsmanCredentials); 177 | return config; 178 | } 179 | 180 | @Override 181 | public XmlConfig systemEraseServer(SystemEraseRequest request) throws Exception { 182 | Credential credential = request.getCredential(); 183 | WsmanCredentials wsmanCredentials = new WsmanCredentials(credential.getAddress(), credential.getUserName(), 184 | credential.getPassword()); 185 | XmlConfig config = configAdapter.performSystemErase(wsmanCredentials, request.getComponentNames()); 186 | return config; 187 | } 188 | 189 | @Override 190 | public String testShareAccessablity(ServerAndNetworkShareRequest request) throws Exception { 191 | WsmanCredentials wsmanCredentials = new WsmanCredentials(request.getServerIP(), request.getServerUsername(), 192 | request.getServerPassword()); 193 | 194 | String result = configAdapter.verifyServerNetworkShareConnectivity(wsmanCredentials, getNetworkShare(request)); 195 | return result; 196 | } 197 | 198 | @Override 199 | public XmlConfig backupServerImage(ServerAndNetworkShareImageRequest request) throws Exception { 200 | WsmanCredentials wsmanCredentials = new WsmanCredentials(request.getServerIP(), request.getServerUsername(), 201 | request.getServerPassword()); 202 | 203 | NetworkShare networkShare = new NetworkShare(); 204 | networkShare.setShareType(getShareTypeEnum(request.getShareType())); 205 | networkShare.setShareName(request.getShareName()); 206 | networkShare.setShareAddress(request.getShareAddress()); 207 | networkShare.setFileName(request.getFileName()); 208 | networkShare.setShareUserName(request.getShareUsername()); 209 | networkShare.setSharePassword(request.getSharePassword()); 210 | 211 | XmlConfig config = configAdapter.backupServerImage(wsmanCredentials, networkShare, request.getPassPhrase(), 212 | request.getImageName(), request.getWorkgroup(), request.getScheduleStartTime(), request.getUntilTime()); 213 | 214 | return config; 215 | } 216 | 217 | @Override 218 | public XmlConfig restoreServerImage(ServerAndNetworkShareImageRequest request) throws Exception { 219 | WsmanCredentials wsmanCredentials = new WsmanCredentials(request.getServerIP(), request.getServerUsername(), 220 | request.getServerPassword()); 221 | 222 | NetworkShare networkShare = new NetworkShare(); 223 | networkShare.setShareType(getShareTypeEnum(request.getShareType())); 224 | networkShare.setShareName(request.getShareName()); 225 | networkShare.setShareAddress(request.getShareAddress()); 226 | networkShare.setFileName(request.getFileName()); 227 | networkShare.setShareUserName(request.getShareUsername()); 228 | networkShare.setSharePassword(request.getSharePassword()); 229 | 230 | XmlConfig config = configAdapter.restoreServerImage(wsmanCredentials, networkShare, request.getPassPhrase(), 231 | request.getImageName(), request.getWorkgroup(), request.getScheduleStartTime(), request.getUntilTime(), request.getPreserveVDConfig()); 232 | return config; 233 | } 234 | 235 | private SHARE_TYPES getShareTypeEnum(int type) { 236 | switch (type) { 237 | case 0: 238 | return SHARE_TYPES.NFS; 239 | case 2: 240 | return SHARE_TYPES.CIFS; 241 | } 242 | return null; 243 | } 244 | 245 | /** 246 | * This Method extracts the List of ServerComponents for a given Server and 247 | * Network share request 248 | * 249 | * @param request 250 | * @return List of ServerComponents 251 | * @throws Exception 252 | */ 253 | private List extractComponents(ServerAndNetworkShareRequest request) throws Exception { 254 | List serverComponents = null; 255 | try { 256 | SystemConfiguration systemConfig = ConfigurationUtils.getSystemConfiguration(request.getFilePathName()); 257 | serverComponents = getServerComponents(systemConfig, request); 258 | } catch (Exception e) { 259 | e.printStackTrace(); 260 | throw e; 261 | } 262 | return serverComponents; 263 | } 264 | 265 | /** 266 | * This method gives the list of ServerComponents for a given 267 | * SystemConfiguration and ServerAndNetworkSharerequest 268 | * 269 | * @param systemConfig- 270 | * The SystemConfiguration object of XML Configuration file 271 | * @param request- 272 | * The ServerAndNetworkShareRequest 273 | * @return List of ServerComponents in a SystemConfiguration 274 | * @throws Exception 275 | */ 276 | private List getServerComponents(SystemConfiguration systemConfig, 277 | ServerAndNetworkShareRequest request) throws Exception { 278 | List extractedComponents = new LinkedList(); 279 | 280 | try { 281 | List serverComponents = systemConfig.getServerComponents(); 282 | List componentNames = request.getComponentNames(); 283 | List temp = new LinkedList(); 284 | 285 | if (CollectionUtils.isNotEmpty(componentNames)) { 286 | for (String reqCompName : componentNames) { 287 | if (StringUtils.isNotBlank(reqCompName)) { 288 | temp.add(reqCompName); 289 | } 290 | } 291 | 292 | if (CollectionUtils.isNotEmpty(temp)) { 293 | for (String componentName : temp) { 294 | for (ServerComponent serverComponent : serverComponents) { 295 | if (StringUtils.equals(componentName, serverComponent.getFQDD())) { 296 | extractedComponents.add(serverComponent); 297 | } 298 | } 299 | } 300 | } else { 301 | extractedComponents.addAll(serverComponents); 302 | } 303 | 304 | } else { 305 | extractedComponents.addAll(serverComponents); 306 | } 307 | 308 | } catch (Exception e) { 309 | e.printStackTrace(); 310 | throw e; 311 | } 312 | return extractedComponents; 313 | } 314 | 315 | @Override 316 | public List updateComponents(ComponentList request, boolean forceUpdate) throws Exception { 317 | return updateConfigurationFile(request, forceUpdate); 318 | } 319 | 320 | /** 321 | * This Method updates the XML Configuration File for a given Component 322 | * Lists to be updated 323 | * 324 | * @param request- 325 | * The ComponentList request 326 | * @return the list of updated ServerComponents 327 | * @throws Exception 328 | */ 329 | private List updateConfigurationFile(ComponentList request, boolean forceUpdate) throws Exception { 330 | List updatedServerComponents = null; 331 | try { 332 | if (null != request) 333 | { 334 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 335 | DocumentBuilder db = dbf.newDocumentBuilder(); 336 | String filePathName = request.getServerAndNetworkShareRequest().getFilePathName(); 337 | logger.info("updateConfigurationFile: File Name from updated request:: " + filePathName); 338 | File xml = new File(filePathName); 339 | Document document = db.parse(xml); 340 | updatedServerComponents = updateConfigurationXMLXPath(document, request.getServerComponents(), forceUpdate); 341 | 342 | TransformerFactory transformerFactory = TransformerFactory.newInstance(); 343 | Transformer transformer = transformerFactory.newTransformer(); 344 | DOMSource source = new DOMSource(document); 345 | StreamResult result = new StreamResult(xml); 346 | transformer.transform(source, result); 347 | logger.info("updateConfigurationFile: updated writing to: " + filePathName); 348 | } 349 | } catch (Exception e) { 350 | e.printStackTrace(); 351 | throw e; 352 | } 353 | return updatedServerComponents; 354 | 355 | } 356 | 357 | /* 358 | * (non-Javadoc) initializes the SCP Micro Service 359 | */ 360 | @Override 361 | public Boolean initializeSCPService(ServerAndNetworkShareRequest request) throws Exception { 362 | updateRequestDetails(request); 363 | Boolean mounted = ConfigurationUtils.mount(request, yamlConfig); 364 | if (mounted && !ConfigurationUtils.fileExist(request.getFilePathName())) { 365 | logger.info("initializeSCPService: File doesn't exist. Exporting the config file from ther server"); 366 | String mode = EXPORT_MODE.NORMAL.getValue(); 367 | exportConfiguration(request, mode); 368 | } else { 369 | logger.info("initializeSCPService: File already exist. Skipping export of file to " 370 | + request.getFilePathName()); 371 | } 372 | return mounted; 373 | } 374 | 375 | /** 376 | * This Method updates the network share filepathName, In case of blank 377 | * ShareAddress file name will be unique otherwise uses the requested 378 | * filePathName 379 | * 380 | * @param serverAndNetworkShareRequest 381 | * @throws Exception 382 | */ 383 | private void updateRequestDetails(ServerAndNetworkShareRequest serverAndNetworkShareRequest) throws Exception { 384 | try { 385 | String filePathName = ""; 386 | if (null != serverAndNetworkShareRequest) { 387 | String fileName = serverAndNetworkShareRequest.getFileName(); 388 | if (StringUtils.isBlank(fileName)) { 389 | logger.info( 390 | "updateRequestDetails: No FileName in Request. Generating Random FileName and updating the request"); 391 | fileName = ConfigurationUtils.getUniqueFileName(); 392 | serverAndNetworkShareRequest.setFileName(fileName); 393 | serverAndNetworkShareRequest.setRandomFile(true); 394 | } 395 | String randomShareName = ConfigurationUtils.getUniqueFileName(); 396 | serverAndNetworkShareRequest.setSharePath(randomShareName); 397 | filePathName = "/shares/remote/" + randomShareName + "/" + fileName; 398 | serverAndNetworkShareRequest.setFilePathName(filePathName); 399 | logger.info("updateRequestDetails: FilePathName: " + filePathName); 400 | } 401 | } catch (Exception e) { 402 | e.printStackTrace(); 403 | throw e; 404 | } 405 | } 406 | 407 | /** 408 | * Gets the network share. 409 | * 410 | * @param request the ServerAndNetworkShareRequest 411 | * @return the network share 412 | */ 413 | private NetworkShare getNetworkShare(ServerAndNetworkShareRequest request) { 414 | NetworkShare networkShare = new NetworkShare(); 415 | networkShare.setShareType(getShareTypeEnum(request.getShareType())); 416 | networkShare.setShareName(request.getShareName()); 417 | networkShare.setShareAddress(request.getShareAddress()); 418 | networkShare.setFileName(request.getFileName()); 419 | networkShare.setShareUserName(request.getShareUsername()); 420 | networkShare.setSharePassword(request.getSharePassword()); 421 | return networkShare; 422 | } 423 | 424 | @SuppressWarnings("unchecked") 425 | @Override 426 | public SystemBiosSettings getBiosSettings(ServerRequest request) throws Exception { 427 | WsmanCredentials wsmanCredentials = new WsmanCredentials(request.getServerIP(), request.getServerUsername(), 428 | request.getServerPassword()); 429 | Map result = (Map) inventoryAdapter.collectBios(wsmanCredentials); 430 | SystemBiosSettings biosSettings = extractDCIMBIOS(result); 431 | List bootSourceSettings = getBootSourceSettings(wsmanCredentials); 432 | biosSettings.setBootSourceSettings(bootSourceSettings); 433 | 434 | return biosSettings; 435 | } 436 | 437 | @SuppressWarnings("unchecked") 438 | private List getBootSourceSettings(WsmanCredentials wsmanCredentials) throws Exception { 439 | List dcimBootSourceSettings = null; 440 | try { 441 | Map result = (Map) inventoryAdapter.collectBoot(wsmanCredentials); 442 | 443 | if (null != result) { 444 | TypeRef> typeRef = new TypeRef>() {}; 445 | dcimBootSourceSettings = JsonPath.using(jsonPathConfiguration).parse(result.get("DCIM_BootSourceSetting")).read("$[*]", typeRef); 446 | } 447 | } catch (Exception e) { 448 | throw e; 449 | } 450 | return dcimBootSourceSettings; 451 | } 452 | 453 | private SystemBiosSettings extractDCIMBIOS(Map result) throws Exception { 454 | SystemBiosSettings systemBiosSetting = null; 455 | try { 456 | if (null != result) { 457 | TypeRef> typeRef = new TypeRef>() {}; 458 | List dcimBIOSEnumerations = JsonPath.using(jsonPathConfiguration).parse(result.get("DCIM_BIOSEnumeration")).read("$[*]", typeRef); 459 | 460 | systemBiosSetting = getSystemBios(dcimBIOSEnumerations); 461 | 462 | } 463 | } catch (Exception e) { 464 | throw e; 465 | } 466 | return systemBiosSetting; 467 | } 468 | 469 | private SystemBiosSettings getSystemBios(List dcimBIOSEnumerations) throws Exception { 470 | SystemBiosSettings systemBiosSetting = new SystemBiosSettings(); 471 | try { 472 | if (CollectionUtils.isNotEmpty(dcimBIOSEnumerations)) { 473 | List systemAttributes = new LinkedList(); 474 | Map> attributePossibleValuesMap = new HashMap>(); 475 | 476 | 477 | for (DCIM_BIOSEnumeration dcimBios: dcimBIOSEnumerations) { 478 | String attributeName = dcimBios.getAttributeName(); 479 | String attributeValue = dcimBios.getCurrentValue(); 480 | ArrayList possibleValues = dcimBios.getPossibleValues(); 481 | 482 | Attribute attribute = new Attribute(); 483 | attribute.setName(attributeName); 484 | attribute.setValue(attributeValue); 485 | systemAttributes.add(attribute); 486 | 487 | attributePossibleValuesMap.put(attributeName, possibleValues); 488 | } 489 | 490 | if (CollectionUtils.isNotEmpty(systemAttributes) && null != attributePossibleValuesMap) { 491 | systemBiosSetting.setAttributes(systemAttributes); 492 | systemBiosSetting.setPossibleValuesForAttributes(attributePossibleValuesMap); 493 | } 494 | } 495 | } catch (Exception e) { 496 | throw e; 497 | } 498 | return systemBiosSetting; 499 | } 500 | 501 | @Override 502 | public ConfigureBiosResult configureBios(BiosSetupRequest request) throws Exception { 503 | ConfigureBiosResult biosResult = new ConfigureBiosResult(); 504 | try { 505 | 506 | if (null != request && null != request.getServerRequest()) { 507 | ServerRequest serverRequest = request.getServerRequest(); 508 | WsmanCredentials wsmanCredentials = new WsmanCredentials(serverRequest.getServerIP(), 509 | serverRequest.getServerUsername(), serverRequest.getServerPassword()); 510 | 511 | SystemBiosSettings serverBiosSettings = getBiosSettings(request.getServerRequest()); 512 | 513 | Map filteredAttributesToUpdate = getFilteredAttributesToUpdate(request.getAttributes(), serverBiosSettings); 514 | 515 | String biosAtrributesUpdateResult = updateAttributes(wsmanCredentials, filteredAttributesToUpdate); 516 | biosResult.setBiosUpdateAttributesResult(biosAtrributesUpdateResult); 517 | biosResult.setUpdatedAttributes(filteredAttributesToUpdate); 518 | 519 | List serverBootSourceSettings = serverBiosSettings.getBootSourceSettings(); 520 | 521 | List filteredInstanceIdsForBootSeq = getInstanceIds(request.getBiosBootSequenceOrder(), serverBootSourceSettings); 522 | List filteredInstanceIdsForHddSeq = getInstanceIds(request.getHddSequenceOrder(), serverBootSourceSettings); 523 | String changeBootOrderSeqResult = changeBootOrderSequence(wsmanCredentials, filteredInstanceIdsForBootSeq, BOOTSOURCE_IPL); 524 | biosResult.setChangeBootOrderSequenceMessage(changeBootOrderSeqResult); 525 | String changeHddSeqResult = changeBootOrderSequence(wsmanCredentials, filteredInstanceIdsForHddSeq, BOOTSOURCE_BCV); 526 | biosResult.setChangeHddSequenceMessage(changeHddSeqResult); 527 | 528 | List devicesToEnable = request.getEnableBootDevices(); 529 | CollectionUtils.filter(devicesToEnable, componentPredicate.filterEnableDisableDevices(serverBootSourceSettings, true)); 530 | List filteredInstanceIdsForBootEnable = getInstanceIds(devicesToEnable, serverBootSourceSettings); 531 | 532 | List devicesToDisable = request.getDisableBootDevices(); 533 | CollectionUtils.filter(devicesToDisable, componentPredicate.filterEnableDisableDevices(serverBootSourceSettings, false)); 534 | List filteredInstanceIdsForBootDisable = getInstanceIds(devicesToDisable, serverBootSourceSettings); 535 | 536 | String bootSourceEnableResult = changeBootSourceState(wsmanCredentials, filteredInstanceIdsForBootEnable, true, BOOTSOURCE_IPL); 537 | biosResult.setEnableBootDevicesResult(bootSourceEnableResult); 538 | String bootSourceDisableResult = changeBootSourceState(wsmanCredentials, filteredInstanceIdsForBootDisable, false, BOOTSOURCE_IPL); 539 | biosResult.setDisableBootDevicesResult(bootSourceDisableResult); 540 | 541 | 542 | 543 | if (StringUtils.equals(biosAtrributesUpdateResult, THE_COMMAND_WAS_SUCCESSFUL) 544 | || StringUtils.equals(changeBootOrderSeqResult, COMPLETED_WITH_NO_ERROR) 545 | || StringUtils.equals(changeHddSeqResult, COMPLETED_WITH_NO_ERROR) 546 | || StringUtils.equals(bootSourceEnableResult, COMPLETED_WITH_NO_ERROR) 547 | || StringUtils.equals(bootSourceDisableResult, COMPLETED_WITH_NO_ERROR)) { 548 | Map cmdResult = configAdapter.createTargetConfigJob(wsmanCredentials, BIOS_SETUP_1_1, 549 | request.getRebootJobType(), request.getScheduledStartTime(), request.getUntilTime()); 550 | 551 | if (null != cmdResult && !cmdResult.isEmpty()) { 552 | 553 | if (cmdResult.containsKey(JOB_ID) && StringUtils.isNotBlank(cmdResult.get(JOB_ID))) { 554 | String jobId = cmdResult.get(JOB_ID); 555 | logger.info("configureBios: result: JobId: " + jobId); 556 | biosResult.setJobId(jobId); 557 | if (StringUtils.equals(request.getScheduledStartTime(), "TIME_NOW")) { 558 | XmlConfig xmlConfig = (XmlConfig) configAdapter.pollJobStatus(wsmanCredentials, jobId, TIME_DELAY_MILLISECONDS, POLL_JOB_RETRY); 559 | biosResult.setXmlConfig(xmlConfig); 560 | } else { 561 | XmlConfig xmlConfig = new XmlConfig(); 562 | xmlConfig.setJobID(jobId); 563 | xmlConfig.setResult(XmlConfig.JobStatus.SUCCESS.toString()); 564 | xmlConfig.setMessage(messageSource.getMessage("Request.ConfigureBios.Success.WithScheduledTime", null, Locale.getDefault())); 565 | biosResult.setXmlConfig(xmlConfig); 566 | } 567 | } else if (cmdResult.containsKey(MESSAGE) && StringUtils.isNotBlank(cmdResult.get(MESSAGE))) { 568 | logger.info("No JobID retrieved from CreateTargedConfigJob"); 569 | String messageFromConfigJob = cmdResult.get(MESSAGE); 570 | biosResult = new ConfigureBiosResult(); 571 | biosResult.setConfigBiosMessage(messageFromConfigJob); 572 | XmlConfig xmlConfig = new XmlConfig(); 573 | xmlConfig.setResult(XmlConfig.JobStatus.FAILURE.toString()); 574 | xmlConfig.setMessage(messageFromConfigJob); 575 | } 576 | } 577 | } 578 | } 579 | } catch (Exception e) { 580 | throw e; 581 | } 582 | return biosResult; 583 | 584 | } 585 | 586 | /** 587 | * Gets the attributes to update. 588 | * 589 | * @param attributes the attributes 590 | * @param serverBiosSettings the configured ServerBiosSettings 591 | * @return the attributes to update 592 | * @throws Exception the exception 593 | */ 594 | private Map getFilteredAttributesToUpdate(List attributes, 595 | SystemBiosSettings serverBiosSettings) throws Exception { 596 | Map filteredAttributes = new HashMap(); 597 | try { 598 | CollectionUtils.select(attributes, componentPredicate.filterAttributes(serverBiosSettings, filteredAttributes)); 599 | } catch (Exception e) { 600 | throw e; 601 | } 602 | return filteredAttributes; 603 | 604 | } 605 | 606 | /** 607 | * Gets the instance ids. 608 | * 609 | * @param devices the devices 610 | * @param serverBootSourceSettings the server boot source settings 611 | * @return the instance ids 612 | * @throws Exception the exception 613 | */ 614 | private List getInstanceIds(List devices, 615 | List serverBootSourceSettings) throws Exception { 616 | List filteredInstanceIdsForDevices = new LinkedList(); 617 | try { 618 | CollectionUtils.select(devices, componentPredicate.filterInstanceIds(serverBootSourceSettings, filteredInstanceIdsForDevices)); 619 | } catch (Exception e) { 620 | throw e; 621 | } 622 | return filteredInstanceIdsForDevices; 623 | } 624 | 625 | /** 626 | * Update attributes. 627 | * 628 | * @param wsmanCredentials the wsman credentials 629 | * @param attributesToUpdate the attributes to update 630 | * @return the string Result 631 | * @throws Exception the exception 632 | */ 633 | private String updateAttributes(WsmanCredentials wsmanCredentials, Map attributesToUpdate) 634 | throws Exception { 635 | String result = messageSource.getMessage("No.Bios.Attributes", null, Locale.getDefault()); 636 | try { 637 | if (null != wsmanCredentials && null != attributesToUpdate && !attributesToUpdate.isEmpty()) { 638 | result = configAdapter.updateBiosAttributes(wsmanCredentials, attributesToUpdate, false); 639 | logger.info("UpdateAttribute Result: " + result); 640 | } 641 | 642 | } catch (Exception e) { 643 | throw e; 644 | } 645 | return result; 646 | } 647 | 648 | /** 649 | * Change boot source state. 650 | * 651 | * @param wsmanCredentials the wsman credentials 652 | * @param instanceIdList the instance id list 653 | * @param isEnabled the is enabled 654 | * @param instanceType the instance type 655 | * @return the string Result 656 | * @throws Exception the exception 657 | */ 658 | private String changeBootSourceState(WsmanCredentials wsmanCredentials, List instanceIdList, boolean isEnabled, 659 | String instanceType) throws Exception { 660 | String result = messageSource.getMessage("No.BootDevices.EnableDisable", null, Locale.getDefault()); 661 | try { 662 | if (null != wsmanCredentials && CollectionUtils.isNotEmpty(instanceIdList) 663 | && StringUtils.isNotBlank(instanceType)) { 664 | result = configAdapter.changeBootSourceState(wsmanCredentials, instanceIdList, isEnabled, instanceType); 665 | logger.info("ChangeBootSourceState Result: " + result); 666 | if (StringUtils.equals(result, "0")) { 667 | result = COMPLETED_WITH_NO_ERROR; 668 | } else { 669 | result = "Failed. Check the logs for the detailed failure."; 670 | } 671 | } 672 | } catch (Exception e) { 673 | throw e; 674 | } 675 | return result; 676 | } 677 | 678 | /** 679 | * Change boot order sequence. 680 | * 681 | * @param wsmanCredentials the wsman credentials 682 | * @param instanceIdList the instance id list 683 | * @param instanceType the BootSourceType type 684 | * @return the string Result 685 | * @throws Exception the exception 686 | */ 687 | private String changeBootOrderSequence(WsmanCredentials wsmanCredentials, List instanceIdList, String instanceType) 688 | throws Exception { 689 | String result = messageSource.getMessage("No.Devices.ChangeSequenceOrder", null, Locale.getDefault()); 690 | try { 691 | if (null != wsmanCredentials && CollectionUtils.isNotEmpty(instanceIdList) 692 | && StringUtils.isNotBlank(instanceType)) { 693 | result = configAdapter.changeBootOrder(wsmanCredentials, instanceType, instanceIdList); 694 | logger.info("changeBootOrderSequence Result: " + result); 695 | if (StringUtils.equals(result, "0")) { 696 | result = COMPLETED_WITH_NO_ERROR; 697 | } else { 698 | result = "Failed. Check the logs for the detailed failure."; 699 | } 700 | } 701 | } catch (Exception e) { 702 | throw e; 703 | } 704 | return result; 705 | } 706 | 707 | private List updateConfigurationXMLXPath(Document xmlDocument, 708 | final List serverComponents, 709 | boolean forceUpdate) throws XPathExpressionException 710 | { 711 | final Set serverComponentSet = new LinkedHashSet<>(); 712 | if (CollectionUtils.isNotEmpty(serverComponents)) 713 | { 714 | final String xpathFindComponentAttribute = "//SystemConfiguration/Component[@FQDD='%s']/Attribute[@Name='%s']"; 715 | final String xpathFindComponentAttributeComment = "//SystemConfiguration/Component[@FQDD='%s']//comment()[contains(.,'Name=\"%s\"')]"; 716 | final String xpathFindComponentSubComponentAttribute = "//SystemConfiguration/Component[@FQDD='%s']/Component[@FQDD='%s']/Attribute[@Name='%s']"; 717 | final String xpathFindComponentSubComponentAttributeComment = "//SystemConfiguration/Component[@FQDD='%s']/Component[@FQDD='%s']//comment()[contains(.,'Name=\"%s\"')]"; 718 | final String xpathFindComponentSubComponentNestedComponentAttribute = "//SystemConfiguration/Component[@FQDD='%s']/Component[@FQDD='%s']/Component[@FQDD='%s']/Attribute[@Name='%s']"; 719 | final String xpathFindComponentSubComponentNestedComponentAttributeComment = "//SystemConfiguration/Component[@FQDD='%s']/Component[@FQDD='%s']/Component[@FQDD='%s']//comment()[contains(.,'Name=\"%s\"')]"; 720 | 721 | XPathFactory xPathfactory = XPathFactory.newInstance(); 722 | XPath xpath = xPathfactory.newXPath(); 723 | for (ServerComponent component : serverComponents) 724 | { 725 | boolean updated = false; 726 | if (CollectionUtils.isNotEmpty(component.getAttributes())) 727 | { 728 | String attributeExpression = String.format(xpathFindComponentAttribute, component.getFQDD(), "%s"); 729 | String commentedElementExpression = String.format(xpathFindComponentAttributeComment, component.getFQDD(), "%s"); 730 | boolean changed = updateAttributesInDocument(xmlDocument, component.getAttributes(), xpath, attributeExpression, commentedElementExpression, forceUpdate); 731 | if (changed) { 732 | updated = true; 733 | } 734 | } 735 | if (CollectionUtils.isNotEmpty(component.getSubComponents())) 736 | { 737 | for (SubComponent subComponent : component.getSubComponents()) 738 | { 739 | if (CollectionUtils.isNotEmpty(subComponent.getAttributes())) 740 | { 741 | String attributeExpression = String.format(xpathFindComponentSubComponentAttribute, component.getFQDD(), 742 | subComponent.getFQDD(), "%s"); 743 | String commentedElementExpression = String.format(xpathFindComponentSubComponentAttributeComment, component.getFQDD(), 744 | subComponent.getFQDD(), "%s"); 745 | boolean changed = updateAttributesInDocument(xmlDocument, 746 | subComponent.getAttributes(), 747 | xpath, 748 | attributeExpression, 749 | commentedElementExpression, 750 | forceUpdate); 751 | if (changed) { 752 | updated = true; 753 | } 754 | } 755 | if (CollectionUtils.isNotEmpty(subComponent.getNestedComponents())) 756 | { 757 | for (NestedComponent nestedComponent : subComponent.getNestedComponents()) 758 | { 759 | String attributeExpression = String.format(xpathFindComponentSubComponentNestedComponentAttribute, 760 | component.getFQDD(), subComponent.getFQDD(), nestedComponent.getFQDD(), 761 | "%s"); 762 | String commentedElementExpression = String.format(xpathFindComponentSubComponentNestedComponentAttributeComment, 763 | component.getFQDD(), subComponent.getFQDD(), nestedComponent.getFQDD(), 764 | "%s"); 765 | boolean changed = updateAttributesInDocument(xmlDocument, 766 | nestedComponent.getAttributes(), 767 | xpath, 768 | attributeExpression, 769 | commentedElementExpression, 770 | forceUpdate); 771 | if (changed) { 772 | updated = true; 773 | } 774 | } 775 | } 776 | } 777 | } 778 | if (updated) { 779 | serverComponentSet.add(component); 780 | } 781 | } 782 | } 783 | return new ArrayList<>(serverComponentSet); 784 | } 785 | 786 | private boolean updateAttributesInDocument(final Document xmlDocument,final List attributes, final XPath xpath, String attributeExpression, String attributeCommentExpression, boolean forceUpdate) 787 | throws XPathExpressionException 788 | { 789 | boolean updated = false; 790 | List removeAttributes = new ArrayList<>(); 791 | if (CollectionUtils.isNotEmpty(attributes)) { 792 | for (Attribute attribute : attributes) { 793 | final String expression = String.format(attributeExpression, attribute.getName()); 794 | Node attributeElement = (Node) xpath.evaluate(expression, xmlDocument, XPathConstants.NODE); 795 | if (attributeElement != null) { 796 | attributeElement.setTextContent(attribute.getValue()); 797 | updated = true; 798 | } else if (forceUpdate) { 799 | final String commentExpression = String.format(attributeCommentExpression, attribute.getName()); 800 | Node commentNode = (Node) xpath.evaluate(commentExpression, xmlDocument, XPathConstants.NODE); 801 | if (commentNode != null) { 802 | final Node parent = commentNode.getParentNode(); 803 | Element newElement = xmlDocument.createElement("Attribute"); 804 | newElement.setAttribute("Name", attribute.getName()); 805 | newElement.setTextContent(attribute.getValue()); 806 | parent.replaceChild(newElement, commentNode); 807 | updated = true; 808 | } 809 | } else { 810 | removeAttributes.add(attribute); 811 | } 812 | } 813 | if (CollectionUtils.isNotEmpty(removeAttributes)) { 814 | attributes.removeAll(removeAttributes); 815 | } 816 | } 817 | return updated; 818 | } 819 | 820 | } 821 | --------------------------------------------------------------------------------