| | |
| | | |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.http.client.SimpleClientHttpRequestFactory; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | @Configuration |
| | |
| | | |
| | | @Bean |
| | | public RestTemplate getRestTemplate(){ |
| | | return new RestTemplate(); |
| | | SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); |
| | | // 设置连接超时时间(单位:毫秒) |
| | | requestFactory.setConnectTimeout(500); |
| | | // 设置请求超时时间(单位:毫秒) |
| | | requestFactory.setReadTimeout(3000); |
| | | return new RestTemplate(requestFactory); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | private static ThreadPoolExecutor init() { |
| | | //线程池初始化,拒绝策略为丢弃 |
| | | UserThreadFactory userThreadFactory = new UserThreadFactory("br"); |
| | | UserThreadFactory userThreadFactory = new UserThreadFactory("ls"); |
| | | ThreadPoolExecutor pool = new ThreadPoolExecutor(8, 48, 10, TimeUnit.SECONDS, new LinkedBlockingDeque<>(16), userThreadFactory,new ThreadPoolExecutor.AbortPolicy()); |
| | | poolExecutor = pool; |
| | | return pool; |
| | |
| | | } |
| | | |
| | | //批量设置a200均衡仪参数 |
| | | public Object setA200ParamPl(A200ResDto param) { |
| | | public Object setA200ParamPl2(A200ResDto param) { |
| | | Map<Integer,Object> map=new HashMap<>(); |
| | | int size=param.getDevIds().size(); |
| | | try { |
| | | ThreadPoolExecutor poolExecutor = ThreadPoolExecutorFactory.getPoolExecutor(); |
| | | CountDownLatch latch = new CountDownLatch(size); |
| | | for (Integer devId:param.getDevIds()) { |
| | | for (int i=0;i<size;i++) { |
| | | int finaldevId=param.getDevIds().get(i); |
| | | poolExecutor.execute(() -> { |
| | | param.setDevId(devId); |
| | | int finalIIdevId=finaldevId; |
| | | param.setDevId(finalIIdevId); |
| | | ResultA200Dto dto= (ResultA200Dto) setA200Param(param); |
| | | map.put(param.getDevId(),dto); |
| | | map.put(finalIIdevId,dto); |
| | | latch.countDown(); |
| | | }); |
| | | } |
| | | latch.await(10, TimeUnit.MINUTES); |
| | | latch.await(4, TimeUnit.MINUTES); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return new Response().setII(1,true,map,"批量设置a200均衡仪参数"); |
| | | } |
| | | //批量设置a200均衡仪参数 |
| | | public Object setA200ParamPl(A200ResDto param) { |
| | | Map<Integer,Object> map=new HashMap<>(); |
| | | int size=param.getDevIds().size(); |
| | | for (int i=0;i<size;i++) { |
| | | int finaldevId=param.getDevIds().get(i); |
| | | param.setDevId(finaldevId); |
| | | ResultA200Dto dto= (ResultA200Dto) setA200Param(param); |
| | | map.put(finaldevId,dto); |
| | | } |
| | | return new Response().setII(1,true,map,"批量设置a200均衡仪参数"); |
| | | } |
| | |
| | | } |
| | | |
| | | //批量启动a200均衡仪 |
| | | public Response startA200ParamPl(List<Integer> devIds,int type) { |
| | | public Response startA200ParamPl2(List<Integer> devIds,int type) { |
| | | Map<Integer,Object> map=new HashMap<>(); |
| | | try { |
| | | ThreadPoolExecutor poolExecutor = ThreadPoolExecutorFactory.getPoolExecutor(); |
| | |
| | | } |
| | | |
| | | //批量启动a200均衡仪 |
| | | public Response stopA200ParamPl(List<Integer> devIds) { |
| | | public Response startA200ParamPl(List<Integer> devIds,int type) { |
| | | Map<Integer,Object> map=new HashMap<>(); |
| | | for (int devId:devIds) { |
| | | ResultA200Dto dto= (ResultA200Dto) startA200Param(devId,type); |
| | | map.put(devId,dto); |
| | | } |
| | | return new Response().set(1,true,"批量控制a200均衡仪"); |
| | | } |
| | | |
| | | //批量停止a200均衡仪 |
| | | public Response stopA200ParamPl2(List<Integer> devIds) { |
| | | Map<Integer,Object> map=new HashMap<>(); |
| | | try { |
| | | ThreadPoolExecutor poolExecutor = ThreadPoolExecutorFactory.getPoolExecutor(); |
| | |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return new Response().set(1,true,"批量控制a200均衡仪"); |
| | | return new Response().set(1,true,"批量停止a200均衡仪"); |
| | | } |
| | | //批量停止a200均衡仪 |
| | | public Response stopA200ParamPl(List<Integer> devIds) { |
| | | Map<Integer,Object> map=new HashMap<>(); |
| | | for (int devId:devIds) { |
| | | ResultA200Dto dto= (ResultA200Dto) stopA200Param(devId); |
| | | map.put(devId,dto); |
| | | } |
| | | return new Response().set(1,true,"批量停止a200均衡仪"); |
| | | } |
| | | |
| | | //将dto拷贝至param |
| | |
| | | } |
| | | |
| | | //批量设置Actm均衡仪参数 |
| | | public Object setActmParamPl(ActmResDto param) { |
| | | public Object setActmParamPl2(ActmResDto param) { |
| | | Map<Integer,Object> map=new HashMap<>(); |
| | | int size=param.getDevIds().size(); |
| | | try { |
| | |
| | | poolExecutor.execute(() -> { |
| | | param.setDevId(devId); |
| | | ResultA200Dto dto= (ResultA200Dto) setActmParam(param); |
| | | map.put(param.getDevId(),dto); |
| | | map.put(devId,dto); |
| | | latch.countDown(); |
| | | }); |
| | | } |
| | | latch.await(10, TimeUnit.MINUTES); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return new Response().setII(1,true,map,"批量设置Actm均衡仪参数"); |
| | | } |
| | | |
| | | //批量设置Actm均衡仪参数 |
| | | public Object setActmParamPl(ActmResDto param) { |
| | | Map<Integer,Object> map=new HashMap<>(); |
| | | int size=param.getDevIds().size(); |
| | | for (Integer devId:param.getDevIds()) { |
| | | param.setDevId(devId); |
| | | ResultA200Dto dto= (ResultA200Dto) setActmParam(param); |
| | | map.put(devId,dto); |
| | | } |
| | | return new Response().setII(1,true,map,"批量设置Actm均衡仪参数"); |
| | | } |
| | |
| | | |
| | | |
| | | //批量控制Actm均衡仪 |
| | | public Response controllActmParamPl(List<ActmPlContDto> actmPlContDtos) { |
| | | public Response controllActmParamPl2(List<ActmPlContDto> actmPlContDtos) { |
| | | Map<Integer,Object> map=new HashMap<>(); |
| | | try { |
| | | ThreadPoolExecutor poolExecutor = ThreadPoolExecutorFactory.getPoolExecutor(); |
| | |
| | | return new Response().set(1,true,"批量设置Actm均衡仪参数"); |
| | | } |
| | | |
| | | //批量控制Actm均衡仪 |
| | | public Response controllActmParamPl(List<ActmPlContDto> actmPlContDtos) { |
| | | Map<Integer,Object> map=new HashMap<>(); |
| | | for (ActmPlContDto actmPlContDto:actmPlContDtos) { |
| | | ResultActmDto dto= (ResultActmDto) controllerActmParam(actmPlContDto.getDevId(),actmPlContDto.getIndex(),actmPlContDto.getType()); |
| | | map.put(actmPlContDto.getDevId(),dto); |
| | | } |
| | | return new Response().set(1,true,"批量设置Actm均衡仪参数"); |
| | | } |
| | | |
| | | //将dto拷贝至param |
| | | private void copyActmDTO(Object data, DevActmTestparam actmParam) { |
| | | ActmResDto dto= (ActmResDto) data; |
| | |
| | | import com.whyc.dto.ResultActmDto; |
| | | import org.springframework.http.*; |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.web.client.RestClientException; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | public class TestparamHttpUtil { |
| | | |
| | | |
| | | |
| | | //post请求传入form-data 格式 |
| | |
| | | // 设置以表单的方式提交 |
| | | headers.add("Content-Type", MediaType.MULTIPART_FORM_DATA_VALUE); |
| | | HttpEntity< MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(paramMap, headers); |
| | | ResponseEntity<String> response = restTemplate.exchange(url, method, requestEntity,String.class ); |
| | | String results= response.getBody(); |
| | | String results= null; |
| | | try { |
| | | ResponseEntity<String> response = restTemplate.exchange(url, method, requestEntity,String.class ); |
| | | results = response.getBody(); |
| | | } catch (RestClientException e) { |
| | | results=" {\n" + |
| | | " \"code\": \"210\",\n" + |
| | | " \"msg\": \"failed in setting test parameters\",\n" + |
| | | " \"data\": null,\n" + |
| | | " \"count\": 0\n" + |
| | | " }"; |
| | | } |
| | | Object dto= ActionUtil.getGson().fromJson(results, ResultA200Dto.class); |
| | | return dto; |
| | | } |
| | |
| | | // 设置以表单的方式提交 |
| | | headers.add("Content-Type", MediaType.MULTIPART_FORM_DATA_VALUE); |
| | | HttpEntity< MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(paramMap, headers); |
| | | ResponseEntity<String> response = restTemplate.exchange(url, method, requestEntity,String.class ); |
| | | String results= response.getBody(); |
| | | String results= null; |
| | | try { |
| | | ResponseEntity<String> response = restTemplate.exchange(url, method, requestEntity,String.class ); |
| | | results = response.getBody(); |
| | | } catch (RestClientException e) { |
| | | results=" {\n" + |
| | | " \"code\": \"210\",\n" + |
| | | " \"msg\": \"failed in setting test parameters\",\n" + |
| | | " \"data\": null,\n" + |
| | | " \"count\": 0\n" + |
| | | " }"; |
| | | } |
| | | Object dto= ActionUtil.getGson().fromJson(results, ResultActmDto.class); |
| | | return dto; |
| | | } |