Topic Text   Topic Comments (0)   Topic Properties   Topic Information pushparaj.dhole23@gma...
Topic title: tmp Thursday September 1, 2016 09:01:00

Download topic text | View in monospace font | Tab width set to 8 (change to 4)

Files in topic:  
[Jump to] diff.txt   {+856,-0}

[Add General Comment] to topic.

File diff.txt (Revision 1.0) [Add File Comment] [Top]
 
1 diff --git a/vision-remediation-service/pom.xml b/vision-remediation-service/pom.xml
2 index e49bb2a..34e8d77 100644
3 --- a/vision-remediation-service/pom.xml
4 +++ b/vision-remediation-service/pom.xml
5 @@ -2,31 +2,27 @@
6 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
8 <modelVersion>4.0.0</modelVersion>
9 -
10 <groupId>vision-remediation-service</groupId>
11 <artifactId>vision-remediation-service</artifactId>
12 <version>1.0-SNAPSHOT</version>
13 <packaging>pom</packaging>
14 -
15 <name>vision-remediation-service</name>
16 <parent>
17 <groupId>org.springframework.boot</groupId>
18 <artifactId>spring-boot-starter-parent</artifactId>
19 <version>1.3.5.RELEASE</version>
20 </parent>
21 -
22 <properties>
23 <java.version>1.8</java.version>
24 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
25 </properties>
26 -
27 <dependencies>
28 <dependency>
29 <groupId>junit</groupId>
30 <artifactId>junit</artifactId>
31 + <scope>test</scope>
32 </dependency>
33 </dependencies>
34 -
35 <modules>
36 <module>vision-remediation-common</module>
37 <module>vision-remediation-server</module>
38 diff --git a/vision-remediation-service/vision-remediation-common/pom.xml b/vision-remediation-service/vision-remediation-common/pom.xml
39 index 73891d1..54d2b0c 100644
40 --- a/vision-remediation-service/vision-remediation-common/pom.xml
41 +++ b/vision-remediation-service/vision-remediation-common/pom.xml
42 @@ -8,17 +8,14 @@
43 <artifactId>vision-remediation-service</artifactId>
44 <version>1.0-SNAPSHOT</version>
45 </parent>
46 -
47 <artifactId>vision-remediation-common</artifactId>
48 <version>1.0</version>
49 <name>vision-remediation-common</name>
50 <packaging>jar</packaging>
51 -
52 <properties>
53 <java.version>1.8</java.version>
54 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
55 </properties>
56 -
57 <dependencies>
58 <dependency>
59 <groupId>org.springframework.boot</groupId>
60 @@ -31,6 +28,7 @@
61 <dependency>
62 <groupId>junit</groupId>
63 <artifactId>junit</artifactId>
64 + <scope>test</scope>
65 </dependency>
66 <dependency>
67 <groupId>commons-validator</groupId>
68 diff --git a/vision-remediation-service/vision-remediation-common/src/main/java/com/vision/remediation/exceptions/VException.java b/vision-remediation-service/vision-remediation-common/src/main/java/com/vision/remediation/exceptions/VException.java
69 index f9b1190..f64622a 100644
70 --- a/vision-remediation-service/vision-remediation-common/src/main/java/com/vision/remediation/exceptions/VException.java
71 +++ b/vision-remediation-service/vision-remediation-common/src/main/java/com/vision/remediation/exceptions/VException.java
72 @@ -36,18 +36,6 @@ public class VException extends Exception
73 }
74
75 /**
76 - * Parameterized constructor
77 - *
78 - * @param message
79 - * error message
80 - * @param throwable
81 - */
82 - public VException(String message, Throwable throwable)
83 - {
84 - super(message, throwable);
85 - }
86 -
87 - /**
88 *
89 * @param id
90 * error code
91 diff --git a/vision-remediation-service/vision-remediation-common/src/main/java/com/vision/remediation/exceptions/VLocalHostNameException.java b/vision-remediation-service/vision-remediation-common/src/main/java/com/vision/remediation/exceptions/VLocalHostNameException.java
92 index c3b28d9..b6c06b9 100644
93 --- a/vision-remediation-service/vision-remediation-common/src/main/java/com/vision/remediation/exceptions/VLocalHostNameException.java
94 +++ b/vision-remediation-service/vision-remediation-common/src/main/java/com/vision/remediation/exceptions/VLocalHostNameException.java
95 @@ -19,6 +19,19 @@ public class VLocalHostNameException extends VException
96 super(message);
97 }
98
99 + /**
100 + * Parameterized constructor
101 + *
102 + * @param id
103 + * error code
104 + * @param message
105 + * error message
106 + */
107 + public VLocalHostNameException(int id, String message)
108 + {
109 + super(id, message);
110 + }
111 +
112 /***
113 * Parameterized constructor**
114 *
115 diff --git a/vision-remediation-service/vision-remediation-common/src/main/java/com/vision/remediation/util/VUtil.java b/vision-remediation-service/vision-remediation-common/src/main/java/com/vision/remediation/util/VUtil.java
116 index 8bf6193..680e3b7 100644
117 --- a/vision-remediation-service/vision-remediation-common/src/main/java/com/vision/remediation/util/VUtil.java
118 +++ b/vision-remediation-service/vision-remediation-common/src/main/java/com/vision/remediation/util/VUtil.java
119 @@ -199,8 +199,16 @@ public class VUtil
120 @SuppressWarnings("unchecked")
121 public static boolean isListEmpty(Object object)
122 {
123 - List<Object> list = (List<Object>) object;
124 - return list.isEmpty();
125 + if (isList(object))
126 + {
127 + List<Object> list = (List<Object>) object;
128 + return list.isEmpty();
129 + }
130 + else
131 + {
132 + return false;
133 + }
134 +
135 }
136
137 /**
138 @@ -247,7 +255,7 @@ public class VUtil
139 }
140 break;
141 case VConstants.TAG_DEVICES:
142 - if (isList(attributeValue) && !isListEmpty(attributeValue))
143 + if (!isListEmpty(attributeValue))
144 {
145 resultFlag = true;
146 }
147 @@ -259,7 +267,7 @@ public class VUtil
148 }
149 break;
150 case VConstants.TAG_FILES:
151 - if (isList(attributeValue) && !isListEmpty(attributeValue))
152 + if (!isListEmpty(attributeValue))
153 {
154 resultFlag = true;
155 }
156 @@ -289,7 +297,7 @@ public class VUtil
157 }
158 break;
159 case VConstants.TAG_ERRORS:
160 - if (isList(attributeValue))
161 + if (!isListEmpty(attributeValue))
162 {
163 resultFlag = true;
164 }
165 @@ -307,7 +315,7 @@ public class VUtil
166 }
167 break;
168 case VConstants.TAG_MESSAGES:
169 - if (isList(attributeValue))
170 + if (!isListEmpty(attributeValue))
171 {
172 resultFlag = true;
173 }
174 @@ -331,7 +339,7 @@ public class VUtil
175 }
176 break;
177 case VConstants.TAG_DEVICERESULTS:
178 - if (isList(attributeValue))
179 + if (!isListEmpty(attributeValue))
180 {
181 resultFlag = true;
182 }
183 @@ -518,7 +526,7 @@ public class VUtil
184 String errorMessage = null;
185 @SuppressWarnings("unchecked")
186 List<Map<String, Object>> messageList = (List<Map<String, Object>>) responseOutputMap.get(VConstants.TAG_ERRORS);
187 - if (isNotNull(messageList) && !messageList.isEmpty())
188 + if (isNotNull(messageList) && !isListEmpty(messageList))
189 {
190 int firstIndex = 0;
191 Map<String, Object> messageMap = messageList.get(firstIndex);
192 diff --git a/vision-remediation-service/vision-remediation-common/src/main/resources/application.properties b/vision-remediation-service/vision-remediation-common/src/main/resources/application.properties
193 index 5a79de8..8923024 100644
194 --- a/vision-remediation-service/vision-remediation-common/src/main/resources/application.properties
195 +++ b/vision-remediation-service/vision-remediation-common/src/main/resources/application.properties
196 @@ -4,9 +4,9 @@ logging.level.org.springframework=INFO
197 logging.file=/var/log/vision-remediation/${spring.application.name}.log
198
199 #Set Rabbit MQ host, user-name and password
200 -vision.rabbitHost=localhost
201 -vision.rabbitUserName=guest
202 -vision.rabbitPassword=guest
203 +vision.rabbitHost=172.17.219.142
204 +vision.rabbitUserName=admin
205 +vision.rabbitPassword=admin
206
207 ##Set Rabbit MQ exchange and the queues
208 vision.exchange=vision-exchange
209 @@ -21,11 +21,11 @@ vision.replyQueue=vision-remediation-reply
210 vision.receiveTimeOutForInventory=1
211 vision.receiveTimeOutForCompliance=5
212 vision.receiveTimeOutForPrepositioning=5
213 -vision.receiveTimeOutForRemediation=15
214 +vision.receiveTimeOutForRemediation=5
215
216 #Set local TFTP base directory
217 vision.tftpBaseDir=/opt/vce/vision-remediation/protocol/tftp/
218 -vision.tftpHost=localhost
219 +vision.tftpHost=172.17.219.129
220 vision.tmpDir=${java.io.tmpdir}/${spring.application.name}
221 vision.tftpProtocol=tftp
222
223 diff --git a/vision-remediation-service/vision-remediation-server/pom.xml b/vision-remediation-service/vision-remediation-server/pom.xml
224 index 6338d05..7640362 100644
225 --- a/vision-remediation-service/vision-remediation-server/pom.xml
226 +++ b/vision-remediation-service/vision-remediation-server/pom.xml
227 @@ -38,6 +38,7 @@
228 <dependency>
229 <groupId>junit</groupId>
230 <artifactId>junit</artifactId>
231 + <scope>test</scope>
232 </dependency>
233 <dependency>
234 <groupId>org.springframework</groupId>
235 diff --git a/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/AbstractTask.java b/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/AbstractTask.java
236 index bc8d3e2..befa457 100644
237 --- a/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/AbstractTask.java
238 +++ b/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/AbstractTask.java
239 @@ -1,16 +1,23 @@
240
241 package com.vision.remediation.library;
242
243 +import java.io.IOException;
244 import java.util.Map;
245
246 import org.slf4j.Logger;
247 import org.slf4j.LoggerFactory;
248 +import org.springframework.amqp.core.AmqpAdmin;
249 import org.springframework.amqp.core.Message;
250 import org.springframework.amqp.core.MessageProperties;
251 import org.springframework.amqp.core.MessagePropertiesBuilder;
252 +import org.springframework.amqp.rabbit.core.ChannelCallback;
253 import org.springframework.amqp.rabbit.core.RabbitTemplate;
254 import org.springframework.beans.factory.annotation.Autowired;
255 +import org.springframework.stereotype.Service;
256
257 +import com.rabbitmq.client.AMQP.Queue.DeclareOk;
258 +import com.vision.remediation.exceptions.VCallerTerminatedException;
259 +import com.vision.remediation.exceptions.VServiceFailureException;
260 import com.vision.remediation.exceptions.VServiceRequestTimeOutException;
261 import com.vision.remediation.exceptions.VUtilException;
262 import com.vision.remediation.util.VConfig;
263 @@ -20,6 +27,7 @@ import com.vision.remediation.util.VUtil;
264 /**
265 * This class is common for all the services and it provide methods to send and receive messages to Rabbit MQ.
266 */
267 +@Service
268 public abstract class AbstractTask
269 {
270 private static final Logger logger = LoggerFactory.getLogger(AbstractTask.class);
271 @@ -29,6 +37,11 @@ public abstract class AbstractTask
272 @Autowired
273 protected VConfig vConfig;
274 /**
275 + * Rabbit Admin object
276 + */
277 + @Autowired
278 + protected AmqpAdmin amqpAdmin;
279 + /**
280 * Spring AMQP template to communicate with rabbit MQ
281 */
282 @Autowired
283 @@ -39,49 +52,43 @@ public abstract class AbstractTask
284 *
285 * @param vTask
286 * task object
287 + * @param serviceQueueName
288 * @param receiveTimeOutForService
289 * time value to wait for the response from specific service
290 * @return json string containing response from the service
291 * @throws VServiceRequestTimeOutException
292 * service not responding until given timeout value
293 * @throws VUtilException
294 + * @throws VCallerTerminatedException
295 */
296 - public String receiveServiceMessages(VTask vTask, long receiveTimeOutForService) throws VServiceRequestTimeOutException, VUtilException
297 + public String receiveServiceMessages(VTask vTask, String serviceQueueName, long receiveTimeOutForService)
298 + throws VServiceRequestTimeOutException, VUtilException, VCallerTerminatedException
299 {
300 String serviceTaskName = vTask.getTaskState();
301 logger.debug("AbstractTask.receiveMessages() Started for " + serviceTaskName + " service.");
302 String serviceOutputMessage = null;
303 template.setReceiveTimeout(receiveTimeOutForService);
304 - Message serviceReply = template.receive(vConfig.getReplyQueue());
305 - if (serviceReply == null)
306 - {
307 - // Service not responding
308 - String message = VUtil.getFormattedMessage(VConstants.SERVICE_TIME_OUT_ERROR, serviceTaskName);
309 - logger.debug("AbstractTask.receiveMessages(): " + message);
310 - throw new VServiceRequestTimeOutException(VConstants.SERVICE_TIME_OUT_ERROR_ID, message);
311 - }
312 - else
313 + String status = VConstants.STATUS_RUNNING;
314 + while (VUtil.isNotNull(status) && status.equalsIgnoreCase(VConstants.STATUS_RUNNING))
315 {
316 + Message serviceReply = template.receive(vConfig.getReplyQueue());
317 + if (serviceReply == null)
318 + {
319 + // Service not responding clear service queue
320 + amqpAdmin.purgeQueue(serviceQueueName, true);
321 + String message = VUtil.getFormattedMessage(VConstants.SERVICE_TIME_OUT_ERROR, serviceTaskName);
322 + logger.debug("AbstractTask.receiveMessages(): " + message);
323 + throw new VServiceRequestTimeOutException(VConstants.SERVICE_TIME_OUT_ERROR_ID, message);
324 + }
325 serviceOutputMessage = new String(serviceReply.getBody());
326 + logger.debug("AbstractTask.receiveMessages(): converting service response message to map, response:" + serviceOutputMessage);
327 Map<String, Object> serviceOutputMap = VUtil.convertMessageToMap(serviceOutputMessage);
328 - String status = (String) serviceOutputMap.get(VConstants.TAG_STATUS);
329 - if (VUtil.isNotNull(status))
330 + status = (String) serviceOutputMap.get(VConstants.TAG_STATUS);
331 + // forward all the status messages coming from services directly to caller of vision layer.
332 + if (VUtil.isNotNull(status) && status.equalsIgnoreCase(VConstants.STATUS_RUNNING))
333 {
334 - // forward all the status messages coming from services directly to caller of vision layer.
335 - while (status.equalsIgnoreCase(VConstants.STATUS_RUNNING))
336 - {
337 - logger.debug("AbstractTask.receiveMessages(): sending status for " + serviceTaskName);
338 - sendStatusMessages(serviceOutputMessage, vTask);
339 - serviceReply = template.receive(vConfig.getReplyQueue());
340 - serviceOutputMessage = new String(serviceReply.getBody());
341 - serviceOutputMap = VUtil.convertMessageToMap(serviceOutputMessage);
342 - status = (String) serviceOutputMap.get(VConstants.TAG_STATUS);
343 - // Stop sending status message if status tag is not present in the service response
344 - if (status == null)
345 - {
346 - break;
347 - }
348 - }
349 + logger.debug("AbstractTask.receiveMessages(): sending status for " + serviceTaskName);
350 + sendStatusMessages(serviceOutputMessage, vTask);
351 }
352 }
353 logger.debug("AbstractTask.receiveMessages() completed for " + serviceTaskName + " service.");
354 @@ -113,14 +120,51 @@ public abstract class AbstractTask
355 * json string containing progress message to send
356 * @param vTask
357 * task object
358 + * @throws VCallerTerminatedException
359 + * @throws VServiceFailureException
360 */
361 - public void sendStatusMessages(String statusMessage, VTask vTask)
362 + public void sendStatusMessages(String statusMessage, VTask vTask) throws VCallerTerminatedException
363 {
364 logger.debug("AbstractTask.sendStatusMessages() message :" + statusMessage);
365 - String correlationId = (String) vTask.getAttribute(VConstants.TAG_CORRELATIONID);
366 - String queueForSendingStatus = (String) vTask.getAttribute(VConstants.REPLY_TO_QUEUE);
367 - MessageProperties messageProperties = MessagePropertiesBuilder.newInstance().setCorrelationId(correlationId.getBytes()).build();
368 - template.send(queueForSendingStatus, new Message(statusMessage.getBytes(), messageProperties));
369 + String queueForSendingStatus = (String) vTask.getAttribute(VConstants.CALLER_REPLY_TO_QUEUE);
370 + if (isQueueExists(queueForSendingStatus))
371 + {
372 + String correlationId = (String) vTask.getAttribute(VConstants.TAG_CORRELATIONID);
373 + MessageProperties messageProperties = MessagePropertiesBuilder.newInstance().setCorrelationId(correlationId.getBytes()).build();
374 + template.send(queueForSendingStatus, new Message(statusMessage.getBytes(), messageProperties));
375 + }
376 + else
377 + {
378 + // Caller of vision layer has terminated a stop the work-flow
379 + throw new VCallerTerminatedException(VConstants.CALLER_TERMINATED_ERROR_ID, VConstants.CALLER_TERMINATED);
380 + }
381 }
382
383 + /**
384 + * This method check for the queue exist or not
385 + *
386 + * @param queue
387 + * name of queue to check
388 + * @return true queue exist false queue not exist
389 + */
390 + private boolean isQueueExists(String queue)
391 + {
392 + Object declareQueueOk = template.execute(new ChannelCallback<DeclareOk>()
393 + {
394 + @Override
395 + public DeclareOk doInRabbit(com.rabbitmq.client.Channel channel)
396 + {
397 + try
398 + {
399 + return channel.queueDeclarePassive(queue);
400 + }
401 + catch (IOException ioException)
402 + {
403 + return null;
404 + }
405 + }
406 +
407 + });
408 + return VUtil.isNotNull(declareQueueOk);
409 + }
410 }
411 diff --git a/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/ITaskService.java b/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/ITaskService.java
412 index dc5f2a8..adf5195 100644
413 --- a/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/ITaskService.java
414 +++ b/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/ITaskService.java
415 @@ -3,6 +3,7 @@ package com.vision.remediation.library;
416
417 import org.springframework.stereotype.Component;
418
419 +import com.vision.remediation.exceptions.VCallerTerminatedException;
420 import com.vision.remediation.exceptions.VFileProcessException;
421 import com.vision.remediation.exceptions.VServiceFailureException;
422 import com.vision.remediation.exceptions.VServiceRequestTimeOutException;
423 @@ -45,8 +46,10 @@ public interface ITaskService
424 * @throws VServiceFailureException
425 * @throws VServiceRequestTimeOutException
426 * @throws VUtilException
427 + * @throws VCallerTerminatedException
428 */
429 - public VTask executeTask(VTask vTask) throws VUtilException, VServiceRequestTimeOutException, VServiceFailureException;
430 + public VTask executeTask(VTask vTask)
431 + throws VUtilException, VServiceRequestTimeOutException, VServiceFailureException, VCallerTerminatedException;
432
433 /**
434 * This method check whether the valid tags present in service response and add the service response to the vTask attributes list
435 diff --git a/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/VComplianceTask.java b/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/VComplianceTask.java
436 index 7d37e60..d69debc 100644
437 --- a/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/VComplianceTask.java
438 +++ b/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/VComplianceTask.java
439 @@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory;
440 import org.springframework.core.annotation.Order;
441 import org.springframework.stereotype.Component;
442
443 +import com.vision.remediation.exceptions.VCallerTerminatedException;
444 import com.vision.remediation.exceptions.VServiceFailureException;
445 import com.vision.remediation.exceptions.VServiceRequestTimeOutException;
446 import com.vision.remediation.exceptions.VServiceValidationException;
447 @@ -71,14 +72,16 @@ public class VComplianceTask extends AbstractTask implements ITaskService
448 }
449
450 @Override
451 - public VTask executeTask(VTask vTask) throws VUtilException, VServiceRequestTimeOutException, VServiceFailureException
452 + public VTask executeTask(VTask vTask)
453 + throws VUtilException, VServiceRequestTimeOutException, VServiceFailureException, VCallerTerminatedException
454 {
455 logger.debug("VComplianceTask.executeTask() invoked executeTask on vTask object ");
456 String correlationId = (String) vTask.getAttribute(VConstants.TAG_CORRELATIONID);
457 String requestInput = VUtil.convertMessageToString(vTask.getAttribute(VConstants.COMPLIANCE_INPUT));
458 + String serviceQueueName = vConfig.getComplianceQueue();
459 logger.debug("VComplianceTask.executeTask() Sending request for " + vTask.getTaskState());
460 - sendServiceMessages(requestInput, vConfig.getComplianceQueue(), correlationId);
461 - String responseOutput = receiveServiceMessages(vTask, vConfig.getReceiveTimeOutForCompliance());
462 + sendServiceMessages(requestInput, serviceQueueName, correlationId);
463 + String responseOutput = receiveServiceMessages(vTask, serviceQueueName, vConfig.getReceiveTimeOutForCompliance());
464 logger.debug("VComplianceTask.executeTask() Got " + vTask.getTaskState() + " response :" + responseOutput);
465 Map<String, Object> responseOutputMap = VUtil.convertMessageToMap(responseOutput);
466 if (VUtil.isNotNull(responseOutputMap.get(VConstants.TAG_STATUS))
467 diff --git a/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/VInventoryTask.java b/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/VInventoryTask.java
468 index a076ca8..631ba26 100644
469 --- a/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/VInventoryTask.java
470 +++ b/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/VInventoryTask.java
471 @@ -8,16 +8,15 @@ import java.util.Map;
472
473 import org.slf4j.Logger;
474 import org.slf4j.LoggerFactory;
475 -import org.springframework.beans.factory.annotation.Autowired;
476 import org.springframework.core.annotation.Order;
477 import org.springframework.stereotype.Component;
478
479 +import com.vision.remediation.exceptions.VCallerTerminatedException;
480 import com.vision.remediation.exceptions.VServiceFailureException;
481 import com.vision.remediation.exceptions.VServiceRequestTimeOutException;
482 import com.vision.remediation.exceptions.VServiceValidationException;
483 import com.vision.remediation.exceptions.VUtilException;
484 import com.vision.remediation.util.InputOutputMessageAttributes;
485 -import com.vision.remediation.util.VConfig;
486 import com.vision.remediation.util.VConstants;
487 import com.vision.remediation.util.VUtil;
488
489 @@ -30,11 +29,6 @@ import com.vision.remediation.util.VUtil;
490 public class VInventoryTask extends AbstractTask implements ITaskService
491 {
492 private static final Logger logger = LoggerFactory.getLogger(VComplianceTask.class);
493 - /**
494 - * VConfig object to get all the properties
495 - */
496 - @Autowired
497 - private VConfig vceConfig;
498
499 @Override
500 public boolean validate(VTask vTask) throws VServiceValidationException
501 @@ -76,14 +70,16 @@ public class VInventoryTask extends AbstractTask implements ITaskService
502 }
503
504 @Override
505 - public VTask executeTask(VTask vTask) throws VUtilException, VServiceRequestTimeOutException, VServiceFailureException
506 + public VTask executeTask(VTask vTask)
507 + throws VUtilException, VServiceRequestTimeOutException, VServiceFailureException, VCallerTerminatedException
508 {
509 logger.debug("VInventoryTask.executeTask() invoked executeTask on vTask object ");
510 String requestInput = VUtil.convertMessageToString(vTask.getAttribute(VConstants.INVENTORY_INPUT));
511 String correlationId = (String) vTask.getAttribute(VConstants.TAG_CORRELATIONID);
512 + String serviceQueueName = vConfig.getInventoryQueue();
513 logger.debug("VInventoryTask.executeTask() Sending request for " + vTask.getTaskState());
514 - sendServiceMessages(requestInput, vceConfig.getInventoryQueue(), correlationId);
515 - String responseOutput = receiveServiceMessages(vTask, vceConfig.getReceiveTimeOutForInventory());
516 + sendServiceMessages(requestInput, serviceQueueName, correlationId);
517 + String responseOutput = receiveServiceMessages(vTask, serviceQueueName, vConfig.getReceiveTimeOutForInventory());
518 logger.debug("VInventoryTask.executeTask() Got " + vTask.getTaskState() + " response :" + responseOutput);
519 Map<String, Object> responseOutputMap = VUtil.convertMessageToMap(responseOutput);
520 if (VUtil.isNotNull(responseOutputMap.get(VConstants.TAG_STATUS))
521 diff --git a/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/VPrepositioningTask.java b/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/VPrepositioningTask.java
522 index d86dd8b..f92974d 100644
523 --- a/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/VPrepositioningTask.java
524 +++ b/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/VPrepositioningTask.java
525 @@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory;
526 import org.springframework.core.annotation.Order;
527 import org.springframework.stereotype.Component;
528
529 +import com.vision.remediation.exceptions.VCallerTerminatedException;
530 import com.vision.remediation.exceptions.VServiceFailureException;
531 import com.vision.remediation.exceptions.VServiceRequestTimeOutException;
532 import com.vision.remediation.exceptions.VServiceValidationException;
533 @@ -78,14 +79,16 @@ public class VPrepositioningTask extends AbstractTask implements ITaskService
534 }
535
536 @Override
537 - public VTask executeTask(VTask vTask) throws VServiceFailureException, VUtilException, VServiceRequestTimeOutException
538 + public VTask executeTask(VTask vTask)
539 + throws VServiceFailureException, VUtilException, VServiceRequestTimeOutException, VCallerTerminatedException
540 {
541 logger.debug("VPrepositioningTask.executeTask() invoked executeTask on vTask object ");
542 String correlationId = (String) vTask.getAttribute(VConstants.TAG_CORRELATIONID);
543 String requestInput = VUtil.convertMessageToString(vTask.getAttribute(VConstants.PREPOSITIONING_INPUT));
544 + String serviceQueueName = vConfig.getPrepositioningQueue();
545 logger.debug("VPrepositioningTask.executeTask() Sending request for " + vTask.getTaskState());
546 - sendServiceMessages(requestInput, vConfig.getPrepositioningQueue(), correlationId);
547 - String responseOutput = receiveServiceMessages(vTask, vConfig.getReceiveTimeOutForPrepositioning());
548 + sendServiceMessages(requestInput, serviceQueueName, correlationId);
549 + String responseOutput = receiveServiceMessages(vTask, serviceQueueName, vConfig.getReceiveTimeOutForPrepositioning());
550 logger.debug("VPrepositioningTask.executeTask() Got " + vTask.getTaskState() + " response :" + responseOutput);
551 Map<String, Object> responseOutputMap = VUtil.convertMessageToMap(responseOutput);
552 if (VUtil.isNotNull(responseOutputMap.get(VConstants.TAG_STATUS))
553 diff --git a/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/VRemediationTask.java b/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/VRemediationTask.java
554 index 51c2ff9..516ed7b 100644
555 --- a/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/VRemediationTask.java
556 +++ b/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/VRemediationTask.java
557 @@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
558 import org.springframework.core.annotation.Order;
559 import org.springframework.stereotype.Component;
560
561 +import com.vision.remediation.exceptions.VCallerTerminatedException;
562 import com.vision.remediation.exceptions.VFileProcessException;
563 import com.vision.remediation.exceptions.VServiceFailureException;
564 import com.vision.remediation.exceptions.VServiceRequestTimeOutException;
565 @@ -85,14 +86,16 @@ public class VRemediationTask extends AbstractTask implements ITaskService
566 }
567
568 @Override
569 - public VTask executeTask(VTask vTask) throws VUtilException, VServiceRequestTimeOutException, VServiceFailureException
570 + public VTask executeTask(VTask vTask)
571 + throws VUtilException, VServiceRequestTimeOutException, VServiceFailureException, VCallerTerminatedException
572 {
573 logger.debug("VRemediationTask.executeTask() invoked executeTask on vTask object ");
574 String correlationId = (String) vTask.getAttribute(VConstants.TAG_CORRELATIONID);
575 String requestInput = VUtil.convertMessageToString(vTask.getAttribute(VConstants.REMEDIATION_INPUT));
576 + String serviceQueueName = vConfig.getRemediationQueue();
577 logger.debug("VRemediationTask.executeTask() Sending request for " + vTask.getTaskState());
578 - sendServiceMessages(requestInput, vConfig.getRemediationQueue(), correlationId);
579 - String responseOutput = receiveServiceMessages(vTask, vConfig.getReceiveTimeOutForRemediation());
580 + sendServiceMessages(requestInput, serviceQueueName, correlationId);
581 + String responseOutput = receiveServiceMessages(vTask, serviceQueueName, vConfig.getReceiveTimeOutForRemediation());
582 logger.debug("VRemediationTask.executeTask() Got " + vTask.getTaskState() + " response :" + responseOutput);
583 Map<String, Object> responseOutputMap = VUtil.convertMessageToMap(responseOutput);
584 @SuppressWarnings("unchecked")
585 @@ -131,6 +134,8 @@ public class VRemediationTask extends AbstractTask implements ITaskService
586 VUtil.validateListTypeAtrributes(outputDevicesAttributes, devices);
587 // Clean up files from TFTP
588 fileProcessor.deleteFile();
589 + vTask.addAllAttributes(remediationOutput);
590 + vTask.deleteAttribute(VConstants.REMEDIATION_OUTPUT);
591 return vTask;
592 }
593
594 diff --git a/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/VTask.java b/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/VTask.java
595 index 66bd992..31ebd69 100644
596 --- a/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/VTask.java
597 +++ b/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/library/VTask.java
598 @@ -1,7 +1,7 @@
599
600 package com.vision.remediation.library;
601
602 -import java.util.HashMap;
603 +import java.util.LinkedHashMap;
604 import java.util.List;
605 import java.util.Map;
606
607 @@ -36,7 +36,7 @@ public class VTask
608 */
609 public VTask()
610 {
611 - taskAttributes = new HashMap<String, Object>();
612 + taskAttributes = new LinkedHashMap<String, Object>();
613 }
614
615 /**
616 diff --git a/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/service/VListener.java b/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/service/VListener.java
617 index ccd9aba..754b373 100644
618 --- a/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/service/VListener.java
619 +++ b/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/service/VListener.java
620 @@ -8,6 +8,8 @@ import org.springframework.amqp.core.MessageListener;
621 import org.springframework.beans.factory.annotation.Autowired;
622 import org.springframework.stereotype.Component;
623
624 +import com.vision.remediation.exceptions.VCallerTerminatedException;
625 +
626 /**
627 * This is a Vision Remediation Listener Service which will accept the request from CLI and initiate the task work flow
628 *
629 @@ -28,11 +30,17 @@ public class VListener implements MessageListener
630 @Override
631 public void onMessage(Message message)
632 {
633 - logger.debug("******************************************Vision remediation request recieved**************************************");
634 - logger.debug("VListener.onMessage() Vision remediation request recieved : " + new String(message.getBody()));
635 - workFlow.startRemediationProcess(message);
636 - logger.debug("VListener.onMessage() Remediation process completed... response sent successfully...!!");
637 - logger.debug("******************************************Vision remediation response sent**************************************");
638 + try
639 + {
640 + logger.debug("***************************************Vision Remediation process started**************************************");
641 + logger.debug("VListener.onMessage() Vision remediation request recieved : " + new String(message.getBody()));
642 + workFlow.startRemediationProcess(message);
643 + logger.debug("*************************************Vision Remediation process completed**************************************");
644 + }
645 + catch (VCallerTerminatedException exception)
646 + {
647 + logger.error("VListener.onMessage() Exception: " + exception);
648 + }
649 }
650
651 }
652 diff --git a/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/service/VTaskWorkFlow.java b/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/service/VTaskWorkFlow.java
653 index 5abb365..c865f37 100644
654 --- a/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/service/VTaskWorkFlow.java
655 +++ b/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/service/VTaskWorkFlow.java
656 @@ -7,12 +7,14 @@ import java.util.Map;
657
658 import org.slf4j.Logger;
659 import org.slf4j.LoggerFactory;
660 -import org.springframework.amqp.core.AmqpAdmin;
661 import org.springframework.amqp.core.Message;
662 import org.springframework.beans.factory.annotation.Autowired;
663 -import org.springframework.beans.factory.annotation.Lookup;
664 +import org.springframework.beans.factory.config.ConfigurableBeanFactory;
665 +import org.springframework.context.annotation.Scope;
666 +import org.springframework.context.annotation.ScopedProxyMode;
667 import org.springframework.stereotype.Service;
668
669 +import com.vision.remediation.exceptions.VCallerTerminatedException;
670 import com.vision.remediation.exceptions.VException;
671 import com.vision.remediation.exceptions.VFileProcessException;
672 import com.vision.remediation.exceptions.VServiceFailureException;
673 @@ -22,7 +24,6 @@ import com.vision.remediation.exceptions.VUtilException;
674 import com.vision.remediation.library.AbstractTask;
675 import com.vision.remediation.library.ITaskService;
676 import com.vision.remediation.library.VTask;
677 -import com.vision.remediation.util.VConfig;
678 import com.vision.remediation.util.VConstants;
679 import com.vision.remediation.util.VUtil;
680
681 @@ -33,64 +34,43 @@ import com.vision.remediation.util.VUtil;
682 */
683
684 @Service
685 +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE, proxyMode = ScopedProxyMode.TARGET_CLASS)
686 public class VTaskWorkFlow extends AbstractTask
687 {
688 private static Logger logger = LoggerFactory.getLogger(VTaskWorkFlow.class);
689 /**
690 - * This is the list of tasks to be called in the workflow
691 + * This is the list of tasks to be called in the work-flow
692 */
693 @Autowired
694 private List<ITaskService> iTaskServices;
695 /**
696 - * VConfig object to get all the properties
697 - */
698 - @Autowired
699 - private VConfig vceConfig;
700 - /**
701 - * Task object per workflow
702 + * Task object per work-flow
703 */
704 @Autowired
705 private VTask vTask;
706 - /**
707 - * Rabbit Admin object
708 - */
709 - @Autowired
710 - private AmqpAdmin amqpAdmin;
711 -
712 - /**
713 - * This will create new task object for each work flow
714 - *
715 - * @return VTask object
716 - */
717 - @Lookup
718 - public VTask vTask()
719 - {
720 - return new VTask();
721 - }
722
723 /**
724 * This method will start the remediation process
725 *
726 * @param message
727 * input message coming from rabbit MQ containing remediation request
728 + * @throws VServiceFailureException
729 + * @throws VCallerTerminatedException
730 *
731 */
732 - public void startRemediationProcess(Message message)
733 + public void startRemediationProcess(Message message) throws VCallerTerminatedException
734 {
735 String requestInput = new String(message.getBody());
736 String requestOutput = null;
737 try
738 {
739 - logger.debug("VTaskWorkFlow.startRemediationProcess() started");
740 + logger.debug("VTaskWorkFlow.startRemediationProcess() started..");
741
742 // Clear reply queue
743 - amqpAdmin.purgeQueue(vceConfig.getReplyQueue(), true);
744 -
745 - // Creating new bean for VTask each time
746 - vTask = vTask();
747 + amqpAdmin.purgeQueue(vConfig.getReplyQueue(), true);
748
749 // Set the CorrelationId from the input message in task attributes
750 - vTask.addAttribute(VConstants.REPLY_TO_QUEUE, message.getMessageProperties().getReplyTo());
751 + vTask.addAttribute(VConstants.CALLER_REPLY_TO_QUEUE, message.getMessageProperties().getReplyTo());
752
753 // Setting the type value in task attributes - default value
754 vTask.addAttribute(VConstants.TAG_TYPE, VConstants.TYPE_RCM);
755 @@ -98,15 +78,15 @@ public class VTaskWorkFlow extends AbstractTask
756 // convert input message JSOn into map
757 Map<String, Object> visionInput = VUtil.convertMessageToMap(requestInput);
758
759 - // Add the vision_input tag to store the input coming to vision layer in task attributes
760 - vTask.addAttribute(VConstants.VISION_INPUT, VUtil.convertMessageToMap(requestInput));
761 -
762 // Adding input message contents to the task object
763 vTask.addAllAttributes(visionInput);
764
765 // Adding version values in Task as rcmVersion and version both are same
766 vTask.addAttribute(VConstants.TAG_VERSION, vTask.getAttribute(VConstants.TAG_RCMVERSION));
767
768 + // Add the vision_input tag to store the input coming to vision layer in task attributes
769 + vTask.addAttribute(VConstants.VISION_INPUT, VUtil.convertMessageToMap(requestInput));
770 +
771 // Check for valid device type
772 isValidDevice();
773
774 @@ -124,7 +104,6 @@ public class VTaskWorkFlow extends AbstractTask
775 logger.debug("VTaskWorkFlow.startRemediationProcess() After " + vTask.getTaskState() + " VTask :" + vTask.toString());
776 }
777 requestOutput = buildVisionSuccessResponse();
778 - logger.debug("VTaskWorkFlow.startRemediationProcess() completed..");
779 }
780 catch (VServiceValidationException | VServiceFailureException | VServiceRequestTimeOutException | VUtilException
781 | VFileProcessException vException)
782 @@ -140,14 +119,17 @@ public class VTaskWorkFlow extends AbstractTask
783 }
784 }
785 sendStatusMessages(requestOutput, vTask);
786 + logger.debug("VTaskWorkFlow.startRemediationProcess() completed..");
787 }
788
789 /**
790 * This method will send status to caller of the vision layer as workflow has been started
791 *
792 * @throws VUtilException
793 + * @throws VServiceFailureException
794 + * @throws VCallerTerminatedException
795 */
796 - private void sendStatusMessage() throws VUtilException
797 + private void sendStatusMessage() throws VUtilException, VServiceFailureException, VCallerTerminatedException
798 {
799 Map<String, Object> device = vTask.getDevice();
800 String workFlowStartedMessage = VUtil.getFormattedMessage(VConstants.WORKFLOW_STARTED, device.get(VConstants.TAG_TYPE),
801 @@ -168,7 +150,7 @@ public class VTaskWorkFlow extends AbstractTask
802 {
803 // validate the input device type is allowed or not
804 String deviceType = (String) vTask.getDevice().get(VConstants.TAG_TYPE);
805 - if (!(Arrays.asList(vceConfig.getSupportedDevices()).contains(deviceType)))
806 + if (!(Arrays.asList(vConfig.getSupportedDevices()).contains(deviceType)))
807 throw new VServiceValidationException(VConstants.SERVICE_FAILURE_ERROR_ID,
808 VUtil.getFormattedMessage(VConstants.DEVICE_TYPE_NOT_SUPPORTED, deviceType));
809 }
810 @@ -186,7 +168,7 @@ public class VTaskWorkFlow extends AbstractTask
811 device.get(VConstants.TAG_ID));
812 successMessage = VUtil.createStatusMessage(successMessage, VConstants.SERVICE_SUCCESS_MESSAGE_ID, VConstants.STATUS_SUCCESS,
813 VConstants.TAG_MESSAGES, vTask.getTaskAttributes());
814 - logger.debug("VTaskWorkFlows.buildVisionSuccessResponse() returning successMessage :" + successMessage);
815 + logger.debug("VTaskWorkFlows.buildVisionSuccessResponse() returning successStatusMessage :" + successMessage);
816 return successMessage;
817 }
818
819 @@ -213,7 +195,7 @@ public class VTaskWorkFlow extends AbstractTask
820 failureMessage = VUtil.createStatusMessage(vException.getMessage(), vException.getId(), VConstants.STATUS_FAILURE,
821 VConstants.TAG_ERRORS, vTask.getTaskAttributes());
822 }
823 - logger.debug("VTaskWorkFlows.buildVisionFailureResponse() returning failureMessage :" + failureMessage);
824 + logger.debug("VTaskWorkFlows.buildVisionFailureResponse() returning failureStatusMessage :" + failureMessage);
825 return failureMessage;
826 }
827 }
828 diff --git a/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/util/VConstants.java b/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/util/VConstants.java
829 index 96cf00d..95ac8d2 100644
830 --- a/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/util/VConstants.java
831 +++ b/vision-remediation-service/vision-remediation-server/src/main/java/com/vision/remediation/util/VConstants.java
832 @@ -55,6 +55,7 @@ public final class VConstants
833 public static final int SERVICE_FAILURE_ERROR_ID = 403;
834 public static final int SERVICE_TIME_OUT_ERROR_ID = 408;
835 public static final int SERVICE_RUNNING_MESSAGE_ID = 100;
836 + public static final int CALLER_TERMINATED_ERROR_ID = 221;
837 // Remediation workflow status
838 public static final String STATUS_SUCCESS = "success";
839 public static final String STATUS_FAILURE = "failure";
840 @@ -62,7 +63,7 @@ public final class VConstants
841 // Misc
842 public static final String File_Seperator = "/";
843 public static final String TYPE_RCM = "RCM";
844 - public static final String REPLY_TO_QUEUE = "replyToQueueName";
845 + public static final String CALLER_REPLY_TO_QUEUE = "callerReplyToQueueName";
846 public static final int TFTP_TIMOUT = 60000;
847 // Status/error messages
848 public static final String SERVICE_TIME_OUT_ERROR = "{0} service not responding - request time out error.";
849 @@ -71,6 +72,7 @@ public final class VConstants
850 public static final String FITNESS_DEVICE_COMPLAINT = "The device id={0} is already compliant.";
851 public static final String REMEDIATION_SUCCESS = "Vision Remediation process to remediate device of type={0} and id={1} has completed successfully.";
852 public static final String REMEDIATION_FAILURE = "Vision Remediation process to remediate device has failed.";
853 + public static final String CALLER_TERMINATED = "Vision Remediation process to remediate device has been interrupted..caller of vision layer has terminated..";
854 // TFTP error messages
855 public static final String TFTP_SOCKET_ERROR = "Unable to open local UDP socket.";
856 public static final String TFTP_TEMP_FILE_ERROR = "Unable to open temp file.";
 
  
Legend:
Removed 
Changed
 Added

[Add General Comment] to topic.