DBA Data[Home] [Help]

PACKAGE BODY: APPS.FND_SVC_COMPONENT

Source


1 PACKAGE BODY FND_SVC_COMPONENT AS
2 /* $Header: AFSVCMPB.pls 120.4 2006/05/03 07:45:32 nravindr ship $ */
3 
4 ------------------------------------------------------------------------------
5 -- **** PRIVATE VARIABLE - NOT FOR CUSTOMER USE ******
6 -- pv_system_guid - the value of local system guid
7 -- pv_schema_name - the value of local WF schema
8 -- **** PRIVATE VARIABLE - NOT FOR CUSTOMER USE ******
9 pv_system_guid  raw(16);
10 pv_schema_name  varchar2(30);
11 
12 pv_last_agent_name   varchar2(30);
13 pv_last_queue_name   varchar2(80);
14 pv_last_recipients   varchar2(30);
15 
16 pv_install_mode varchar2(30);
17 ------------------------------------------------------------------------------
18 
19 -- Private declarations start
20 
21 e_ContainerNotRunning 		EXCEPTION;
22 
23 Procedure Get_Container_Info(p_Component_Id in number,
24 			   p_Container_Type out nocopy varchar2,
25 			   p_Container_Name out nocopy varchar2);
26 
27 Procedure Raise_Control_Event (p_Component_Id in number default -1,
28 				p_Control_Operation in varchar2,
29 				p_Container_Type in varchar2,
30 				p_CPID in number,
31 				p_Params in varchar2 default null);
32 
33 Function Get_ConcQ_Name (ApplId in number, ConcQID in number) return varchar2;
34 
35 Procedure Get_ConcQ_ID (ConcQName in varchar2, ApplId out nocopy number, ConcQId out nocopy number);
36 
37 PROCEDURE Refresh_Container
38          ( p_container_type     IN VARCHAR2,
39            p_container_name     IN VARCHAR2,
40            p_params		IN VARCHAR2,
41            p_retcode		OUT NOCOPY NUMBER,
42            p_errbuf		OUT NOCOPY VARCHAR2);
43 
47           ( p_component_request_id IN NUMBER)
44 -- Private declarations end
45 
46 PROCEDURE Delete_Request
48 AS
49   l_job_id         fnd_svc_comp_requests.job_id%TYPE;
50 
51 BEGIN
52 
53   --
54   -- NOTE: This is in PL/SQL because it is called both by Execute_Request and
55   --       by the Java code
56   --
57 
58   SELECT job_id
59   INTO l_job_id
60   FROM fnd_svc_comp_requests
61   WHERE component_request_id = p_component_request_id;
62 
63   --
64   -- Delete DBMS_JOB
65   --
66   DBMS_Job.Remove(
67     job => l_job_id);
68 
69   --
70   -- Delete the request
71   --
72   FND_SVC_COMP_REQUESTS_PKG.DELETE_ROW(
73     x_component_request_id => p_component_request_id);
74 
75 END Delete_Request;
76 
77 
78 PROCEDURE Execute_Request
79           ( p_component_request_id IN NUMBER)
80 AS
81 
82   l_component_id       fnd_svc_comp_requests.component_id%TYPE;
83   l_event_name         fnd_svc_comp_requests.event_name%TYPE;
84   l_job_id             fnd_svc_comp_requests.job_id%TYPE;
85   l_event_params       fnd_svc_comp_requests.event_params%TYPE;
86   l_event_frequency    fnd_svc_comp_requests.event_frequency%TYPE;
87   l_requested_by_user  fnd_svc_comp_requests.requested_by_user%TYPE;
88 
89   l_component_name     fnd_svc_components.component_name%TYPE;
90   l_component_type     fnd_svc_components.component_type%TYPE;
91   l_component_status   fnd_svc_components.component_status%TYPE;
92   l_container_type     fnd_svc_components.container_type%TYPE;
93   l_container_name     fnd_svc_components.standalone_container_name%TYPE;
94 
95   l_request_history_id fnd_svc_comp_requests_h.request_history_id%TYPE;
96   l_rowid              VARCHAR2(64);
97   l_Status varchar2(30) := FND_SVC_COMPONENT.pv_adminStatusCompleted;
98 
99   l_ErrorMsg     		VARCHAR2 (4000);
100   l_RetCode      		NUMBER := 0;
101 
102 BEGIN
103 
104   --
105   -- NOTE: This is in PL/SQL because it is called by DBMS_JOB
106   --
107 
108   --
109   -- Retrieve request details
110   --
111   begin
112 
113       SELECT a.component_id, event_name, event_params, event_frequency, requested_by_user, component_name,
114              component_status, component_type, container_type, standalone_container_name
115       INTO l_component_id, l_event_name, l_event_params, l_event_frequency, l_requested_by_user,
116            l_component_name, l_component_status, l_component_type, l_container_type, l_container_name
117       FROM fnd_svc_comp_requests a, fnd_svc_components b
118       WHERE component_request_id = p_component_request_id and
119             a.component_id = b.component_id;
120 
121       IF l_container_type = pv_Container_Type_GSM THEN
122         SELECT concurrent_queue_name
123         INTO l_container_name
124         FROM fnd_svc_components_v
125         WHERE component_id = l_component_id;
126       END IF;
127 
128     EXCEPTION
129     WHEN others then
130     -- WHEN NO_DATA_FOUND then
131 
132     -- What can we do? - nothing
133     -- This is really weird, request is getting executed and
134     -- request is not there? Maybe, request got deleted and job is still
135     -- getting executed. Donot do anything, return
136     -- With the deletion of request, job for future will anyway be deleted
137         if (wf_log_pkg.level_error >= fnd_log.g_current_runtime_level) then
138            wf_log_pkg.STRING(wf_log_pkg.LEVEL_ERROR,
139                             'wf.plsql.FND_SVC_COMPONENT.EXECUTE_REQUEST.request_lookup_failed',
140                             'Could not get request info, SQLCODE: '||SQLCODE);
141         end if;
142         return;
143   END;
144 
145   if (wf_log_pkg.level_exception >= fnd_log.g_current_runtime_level) then
146      wf_log_pkg.STRING (wf_log_pkg.LEVEL_EXCEPTION,
147                         'wf.plsql.FND_SVC_COMPONENT.EXECUTE_REQUEST.executing',
148                         'Request Type: '||l_event_name||
149                         ', Job no.: '||l_job_id||
150                         ', Component_id: '||l_Component_id);
151   end if;
152 
153   if l_event_name = FND_SVC_COMPONENT.pv_Event_Suspend then
154 
155       FND_SVC_COMPONENT.Suspend_Component(l_Component_id, l_RetCode, l_ErrorMsg);
156 
157   elsif l_event_name = FND_SVC_COMPONENT.pv_Event_Resume then
158 
159       FND_SVC_COMPONENT.Resume_Component(l_Component_id, l_RetCode, l_ErrorMsg);
160 
161   elsif l_event_name = FND_SVC_COMPONENT.pv_Event_Stop then
162 
163       FND_SVC_COMPONENT.Stop_Component(l_Component_id, l_RetCode, l_ErrorMsg);
164 
165   elsif l_event_name = FND_SVC_COMPONENT.pv_Event_Start then
166 
167       FND_SVC_COMPONENT.Start_Component(l_Component_id, l_RetCode, l_ErrorMsg);
168 
169   elsif l_event_name = FND_SVC_COMPONENT.pv_Event_Refresh then
170 
171       FND_SVC_COMPONENT.Refresh_Component(l_Component_id, l_event_params, l_RetCode, l_ErrorMsg);
172 
173   else
174 
175       FND_SVC_COMPONENT.Generic_Operation (l_Component_id, l_event_name, l_event_params, l_RetCode, l_ErrorMsg);
176 
177   end if;
178 
179   if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
180      wf_log_pkg.STRING (wf_log_pkg.LEVEL_STATEMENT,
181                        'wf.plsql.FND_SVC_COMPONENT.EXECUTE_REQUEST.executed',
182                        'After component control operation, Return code: '||l_RetCode);
183   end if;
184 
185   if l_RetCode = FND_SVC_COMPONENT.pv_retInvalidComponentState then
186 
187       -- SKIPPED
191 
188       l_Status := FND_SVC_COMPONENT.pv_adminStatusSkipped;
189 
190   elsif l_RetCode <> 0 then -- Container not running or other SQL error
192       -- ERRORED
193       l_Status := FND_SVC_COMPONENT.pv_adminStatusErrored;
194 
195   end if;
196 
197   --
198   -- Delete the request if it's not a recurring request
199   --
200   IF (l_event_frequency is NULL OR
201       l_event_frequency = 0) THEN
202 
203     if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
204        wf_log_pkg.STRING (wf_log_pkg.LEVEL_STATEMENT,
205                          'wf.plsql.FND_SVC_COMPONENT.EXECUTE_REQUEST.frequency',
206                          'Frequency is null, removing job');
207     end if;
208 
209     Delete_Request(p_component_request_id => p_component_request_id);
210 
211   END IF;
212 
213   --
214   -- Audit the request history
215   --
216 
217   if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
218      wf_log_pkg.STRING (wf_log_pkg.LEVEL_STATEMENT,
219                        'wf.plsql.FND_SVC_COMPONENT.EXECUTE_REQUEST.request_audit',
220                        'Request audited with status: '||l_Status);
221   end if;
222 
223   SELECT fnd_svc_comp_requests_h_s.nextval INTO l_request_history_id FROM dual;
224 
225   FND_SVC_COMP_REQUESTS_H_PKG.Insert_Row
226     ( x_rowid => l_rowid
227     , x_request_history_id => l_request_history_id
228     , x_component_id => l_component_id
229     , x_event_name => l_event_name
230     , x_request_status => l_Status
231     , x_requested_by_user => l_requested_by_user
232     , x_completion_date => SYSDATE
233     , x_component_name => l_component_name
234     , x_component_status => l_component_status
235     , x_component_type => l_component_type
236     , x_container_type => l_container_type
237     , x_container_name => l_container_name
238     , x_event_params => l_event_params
239     , x_created_by => 0 -- TODO
240     , x_last_updated_by => 0 -- TODO
241     , x_last_update_login => 0 -- TODO
242     );
243 
244   commit;
245 
246 EXCEPTION
247   WHEN OTHERS THEN
248       -- Can come here only because of some SQL error in FND_SVC_COMP_REQUESTS_H_PKG.Insert_Row
249       -- Still we need to commit;
250       if (wf_log_pkg.level_error >= fnd_log.g_current_runtime_level) then
251          wf_log_pkg.STRING (wf_log_pkg.LEVEL_ERROR,
252                            'wf.plsql.FND_SVC_COMPONENT.EXECUTE_REQUEST.error',
253                            'Unhandled error, SQLCODE: '||SQLCODE);
254       end if;
255       commit;
256 
257 END EXECUTE_REQUEST;
258 
259 
260 FUNCTION Get_OAM_Rolled_Status_By_Type
261          ( p_component_type    IN VARCHAR2)
262          RETURN NUMBER
263 AS
264 
265   l_found_running_flag BOOLEAN := FALSE;
266 
267   CURSOR c_Components
268   IS
269     SELECT c.component_status
270     FROM fnd_svc_components c
271     WHERE c.component_type = NVL(p_component_type, c.component_type);
272 
273 BEGIN
274   --
275   -- Loop through all components
276   --
277   FOR r_Component IN c_Components LOOP
278 
279     --
280     -- If it is in "error", return DOWN immediately
281     --
282     IF (r_Component.component_status IN (pv_Status_Stopped_Error, pv_Status_Deactivated_System)) THEN
283 
284       RETURN pv_OAM_Status_Down;
285 
286     --
287     -- If it is "running", mark it so and exit from the loop
288     --
289     ELSIF (r_Component.component_status IN (pv_Status_Running, pv_Status_Suspended)) THEN
290 
291       l_found_running_flag := TRUE;
292       --EXIT;
293     END IF;
294   END LOOP;
295 
296   --
297   -- If any were "running", return UP
298   --
299   IF l_found_running_flag THEN
300 
301     RETURN pv_OAM_Status_Up;
302 
303   --
304   -- Otherwise, return NA (Not Available/Unknown)
305   --
306   ELSE
307 
308     RETURN pv_OAM_Status_NA;
309 
310   END IF;
311 
312 END Get_OAM_Rolled_Status_By_Type;
313 
314 PROCEDURE Insert_Param_Vals
315           ( p_component_type    IN VARCHAR2
316           , p_component_id      IN NUMBER)
317 AS
318   CURSOR c_params IS
319     SELECT parameter_id
320          , default_parameter_value
321     FROM fnd_svc_comp_params_b
322     WHERE component_type = p_component_type;
323 
324     l_rowid                  VARCHAR2(64);
325     l_component_parameter_id fnd_svc_comp_param_vals.component_parameter_id%TYPE;
326 
327   l_customization_level fnd_svc_components.customization_level%TYPE;
328   l_created_by          NUMBER;
329   l_last_updated_by     NUMBER;
330   l_last_update_login   NUMBER;
331 
332 BEGIN
333 
334   --
335   -- Loop through all parameters for specified component type
336   --
337 
338   FOR param IN c_params LOOP
339 
340     --
341     -- Retrieve next sequence value
342     --
343     SELECT fnd_svc_comp_param_vals_s.nextval
344     INTO l_component_parameter_id
345     FROM dual;
346 
347     --
348     -- Retrieve common data from component
349     --
350     SELECT customization_level, created_by, last_updated_by, last_update_login
351     INTO l_customization_level, l_created_by, l_last_updated_by, l_last_update_login
352     FROM fnd_svc_components
353     WHERE component_id = p_component_id;
354 
358     FND_SVC_COMP_PARAM_VALS_PKG.INSERT_ROW
355     --
356     -- Insert parameter value
357     --
359       ( x_rowid => l_rowid
360       , x_component_parameter_id => l_component_parameter_id
361       , x_component_id => p_component_id
362       , x_parameter_id => param.parameter_id
363       , x_parameter_value => param.default_parameter_value
364       , x_customization_level => l_customization_level
365       , x_created_by => l_created_by
366       , x_last_updated_by => l_last_updated_by
367       , x_last_update_login => l_last_update_login
368       );
369   END LOOP;
370 
371 EXCEPTION
372  WHEN OTHERS THEN
373    WF_CORE.CONTEXT(pv_Package_Name, 'Insert_Param_Vals', p_component_type, p_component_id);
374 
375    RAISE;
376 
377 END Insert_Param_Vals;
378 
379 PROCEDURE Get_Container_Status
380          ( p_container_type     IN VARCHAR2
381          , p_container_name     IN VARCHAR2
382 	 , p_container_status	OUT NOCOPY VARCHAR2
383 	 , p_process_id		OUT NOCOPY NUMBER)
384 AS
385 
386   l_module_name    	 gv$session.module%TYPE;
387   l_module_name_temp     gv$session.module%TYPE;
388   l_action_temp          gv$session.action%TYPE;
389   l_found     		 boolean;
390   l_schema_name          gv$session.SCHEMANAME%TYPE;
391 
392   CURSOR c_containers_running (c_module_name VARCHAR2, c_schema_name VARCHAR2) IS
393     -- SELECT module
394     SELECT module, action
395     FROM gv$session se
396     -- WHERE se.module like c_module_name and se.action is not null;
397     -- Bug fix for 3461327, retrieve the record with largest CPID.
398     WHERE se.module like c_module_name
399     -- Use Schema name to distinguish different service containers running on different
400     -- schema. Bug 3630749
401     and   se.SCHEMANAME like c_schema_name
402     order by se.module desc;
403     -- Action will be set to ACTIVE in start and null when Container is stopping
404 
405 BEGIN
406 
407   if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
408      WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_PROCEDURE,
409                        'wf.plsql.FND_SVC_COMPONENT.Get_Container_Status.begin',
410                        'p_container_type: '||p_container_type||
411                        ', p_container_name:'||p_container_name);
412   end if;
413 
414   p_container_status := pv_Container_Status_Stopped;
415   l_found := FALSE;
416 
417   --
418   -- Set search module name = '<Prefix>:<Container Type>:<Container Name>:%'
419   --
420   l_module_name :=
421     pv_Connection_Name_Prefix || ':' ||
422     p_container_type || ':' ||
423     p_container_name || ':%';
424 
425   -- YOHUANG: Bug Fix for 3630749
426   -- If APPS MODE, append APPS in module name to distinguish with standalone sessions.
427   -- If Apps Mode, Use the WF_SCHEMA to distinguish between different standalone sessions.
428   if (pv_install_mode = 'EMBEDDED') then
429     l_module_name := 'APPS' || ':' || l_module_name;
430     l_schema_name := '%';
431   else
432     l_schema_name := pv_schema_name;
433   end if;
434 
435   FOR rec_running_container IN c_containers_running (l_module_name, l_schema_name) LOOP
436   	l_module_name_temp := rec_running_container.module;
437   	l_action_temp := rec_running_container.action;
438 	l_found := TRUE;
439 	exit;
440   END LOOP;
441 
442   if l_found then
443 	-- Extract and set the p_process_id using l_module_name_temp
444 	-- l_module_name_temp should look like 'SVC:GSM:WFMAILER:5677'
445 	p_process_id := to_number(substr(l_module_name_temp,instr(l_module_name_temp,':',-1,1)+1));
446 
447         -- Action will be set to ACTIVE in start and null when Container is stopping
448         if l_action_temp is null then
449   	    p_container_status := pv_Container_Status_Stopping;
450         else
451   	    p_container_status := pv_Container_Status_Running;
452         end if;
453   END IF;
454 
455 EXCEPTION
456   WHEN OTHERS THEN
457     WF_CORE.CONTEXT(pv_Package_Name, 'Get_Container_Status', p_container_type, p_container_name);
458   RAISE;
459 
460 END Get_Container_Status;
461 
462 PROCEDURE Name_Container_Session
463           ( p_container_type IN VARCHAR2
464           , p_container_name IN VARCHAR2
465 	  , p_process_id IN NUMBER
466 	  , p_action_name IN VARCHAR2)
467 AS
468 
469   l_module_name     gv$session.module%TYPE;
470 
471 BEGIN
472 
473   if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
474      WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_PROCEDURE,
475                        'wf.plsql.FND_SVC_COMPONENT.Name_Container_Session.begin',
476                        'p_container_type: '||p_container_type||
477                        ', p_container_name:'||p_container_name);
478   end if;
479 
480   --
481   -- Set module name = '[APPS]:<Prefix>:<Container Type>:<Container Name>:<Process Id>'
482   --
483   l_module_name :=
484     pv_Connection_Name_Prefix || ':' ||
485     p_container_type || ':' ||
486     p_container_name || ':' ||
487     p_process_id;
488 
489   -- YOHUANG: Bug Fix for 3630749
490   -- If APPS MODE, append APPS in module name to distinguish with standalone sessions.
491   if (pv_install_mode = 'EMBEDDED') then
492     l_module_name := 'APPS' || ':' || l_module_name;
493   end if;
494 
495   DBMS_APPLICATION_INFO.SET_MODULE
496   (
497     module_name => l_module_name
498   , action_name => p_action_name
499   );
500 
501 EXCEPTION
502   WHEN OTHERS THEN
503     WF_CORE.CONTEXT(pv_Package_Name, 'Name_Container_Session', p_container_type,
504 				p_container_name, p_process_id);
505   RAISE;
506 
507 END Name_Container_Session;
511          , p_component_id      IN NUMBER)
508 
509 FUNCTION Retrieve_Parameter_Value
510          ( p_parameter_name    IN VARCHAR2
512          RETURN VARCHAR2
513 AS
514   l_result fnd_svc_comp_param_vals.parameter_value%TYPE;
515 
516 BEGIN
517 
518   SELECT parameter_value
519   INTO l_result
520   FROM fnd_svc_comp_param_vals_v
521   WHERE parameter_name = p_parameter_name
522     AND component_id = p_component_id;
523 
524   RETURN l_result;
525 
526 END Retrieve_Parameter_Value;
527 
528 
529 Function Get_Current_Status(p_Component_Id in NUMBER) return varchar2
530 is
531 	l_CurrentStatus fnd_svc_components.component_status%TYPE;
532 begin
533 	select component_status into l_CurrentStatus
534 		from fnd_svc_components where component_id = p_Component_Id;
535 
536 	return l_CurrentStatus;
537 
538 EXCEPTION
539   WHEN OTHERS THEN
540     WF_CORE.CONTEXT(pv_Package_Name, 'Get_Current_Status', p_Component_Id);
541   RAISE;
542 end Get_Current_Status;
543 
544 
545 PROCEDURE Validate_Operation
546 		(p_Component_Id        IN NUMBER,
547 		p_Control_Operation   IN VARCHAR2,
548 		p_retcode	OUT NOCOPY NUMBER,
549 		p_errbuf	OUT NOCOPY VARCHAR2)
550 is
551 
552 l_isValid boolean := false;
553 l_CurrentStatus fnd_svc_components.component_status%TYPE;
554 
555 begin
556 
557  p_retcode := 0;
558 
559  if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
560     WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_PROCEDURE,
561 		              'wf.plsql.FND_SVC_COMPONENT.IS_OPERATION_VALID.begin',
562                       'p_Component_Id: '||p_Component_Id||
563                       ', p_Control_Operation:'||p_Control_Operation);
564  end if;
565 
566  l_CurrentStatus := Get_Current_Status (p_Component_Id => p_Component_Id);
567 
568  if p_Control_Operation = FND_SVC_COMPONENT.pv_opStart then
569 
570 	if l_CurrentStatus in (FND_SVC_COMPONENT.pv_Status_Stopped,
571 					FND_SVC_COMPONENT.pv_Status_Stopped_Error,
572 					FND_SVC_COMPONENT.pv_Status_Deactivated_User,
573 					FND_SVC_COMPONENT.pv_Status_Deactivated_System) then
574 		l_isValid := true;
575 	else
576 		l_isValid := false;
577 	end if;
578 
579  elsif p_Control_Operation = FND_SVC_COMPONENT.pv_opStop then
580 
581 	if l_CurrentStatus not in (FND_SVC_COMPONENT.pv_Status_Stopped,
582 					FND_SVC_COMPONENT.pv_Status_Stopped_Error,
583 				    	FND_SVC_COMPONENT.pv_Status_Not_Configured,
584 					FND_SVC_COMPONENT.pv_Status_Deactivated_User,
585 					FND_SVC_COMPONENT.pv_Status_Deactivated_System) then
586 		l_isValid := true;
587 	else
588 		l_isValid := false;
589 	end if;
590 
591  elsif p_Control_Operation = FND_SVC_COMPONENT.pv_opSuspend then
592 
593 	if l_CurrentStatus = FND_SVC_COMPONENT.pv_Status_Running then
594 		l_isValid := true;
595 	else
596 		l_isValid := false;
597 	end if;
598 
599  elsif p_Control_Operation = FND_SVC_COMPONENT.pv_opResume then
600 
601 	if l_CurrentStatus = FND_SVC_COMPONENT.pv_Status_Suspended then
602 		l_isValid := true;
603 	else
604 		l_isValid := false;
605 	end if;
606 
607  elsif p_Control_Operation = FND_SVC_COMPONENT.pv_opUpdate then
608 
609 	if l_CurrentStatus in (FND_SVC_COMPONENT.pv_Status_Stopped,
610 				FND_SVC_COMPONENT.pv_Status_Stopped_Error,
611 				FND_SVC_COMPONENT.pv_Status_Not_Configured,
612 				FND_SVC_COMPONENT.pv_Status_Deactivated_User,
613 				FND_SVC_COMPONENT.pv_Status_Deactivated_System) then
614 		l_isValid := true;
615 	else
616 		l_isValid := false;
617 	end if;
618 
619  elsif p_Control_Operation = FND_SVC_COMPONENT.pv_opDelete then
620 
621 	if l_CurrentStatus in (FND_SVC_COMPONENT.pv_Status_Stopped,
622 				FND_SVC_COMPONENT.pv_Status_Stopped_Error,
623 				FND_SVC_COMPONENT.pv_Status_Not_Configured,
624 				FND_SVC_COMPONENT.pv_Status_Deactivated_User,
625 				FND_SVC_COMPONENT.pv_Status_Deactivated_System) then
626 		l_isValid := true;
627 	else
628 		l_isValid := false;
629 	end if;
630 
631  elsif p_Control_Operation = FND_SVC_COMPONENT.pv_opGeneric or
632 	p_Control_Operation = FND_SVC_COMPONENT.pv_opRefresh then
633 
634 	-- Generic operation
635 
636 	if l_CurrentStatus = FND_SVC_COMPONENT.pv_Status_Running then
637 		l_isValid := true;
638 	else
639 		l_isValid := false;
640 	end if;
641 
642  else
643 	l_isValid := false;
644 
645  end if;
646 
647  if not l_isValid then
648 	p_retCode := pv_retInvalidComponentState;
649  	p_errbuf := WF_CORE.TRANSLATE ('SVC_COMP_INVALID_EVENT');
650     if (wf_log_pkg.level_error >= fnd_log.g_current_runtime_level) then
651        WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_ERROR,
652                          'wf.plsql.FND_SVC_COMPONENT.VALIDATE_OPERATION.invalid_event',
653                          'Error code: '||p_retCode||' ,Error desc: '||p_errbuf);
654     end if;
655  END IF;
656 
657 EXCEPTION
658 
659 when others then
660 if SQLCODE <> 0 then
661  	p_retCode := SQLCODE;
662  	p_errbuf :=  SQLERRM;
663 else
664 	p_retCode := pv_retOtherComponentError;
665  	p_errbuf := 'Other non-SQL error';
666 END IF;
667 if (wf_log_pkg.level_error >= fnd_log.g_current_runtime_level) then
668    WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_ERROR,
669                      'wf.plsql.FND_SVC_COMPONENT.VALIDATE_OPERATION.error',
670                      'Error code: '||p_retCode||' ,Error desc: '||p_errbuf);
671 end if;
672 
673 end Validate_Operation;
674 
675 Procedure Get_Container_Info(p_Component_Id in number,
676 			   p_Container_Type out nocopy varchar2,
680 l_Standalone_Container_Name fnd_svc_components.standalone_container_name%TYPE;
677 			   p_Container_Name out nocopy varchar2)
678 is
679 l_Concurrent_Queue_Name fnd_concurrent_queues.concurrent_queue_name%TYPE;
681 begin
682     if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
683         WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_PROCEDURE,
684 	                      'wf.plsql.FND_SVC_COMPONENT.GET_CONTAINER_INFO.begin',
685                           'p_Component_Id: '||p_Component_Id);
686     end if;
687 
688 	select container_type, concurrent_queue_name, standalone_container_name
689 	into p_Container_Type, l_Concurrent_Queue_Name, l_Standalone_Container_Name
690 	from fnd_svc_components_v where component_id = p_Component_Id;
691 
692 	if (p_Container_Type = FND_SVC_COMPONENT.pv_Container_Type_GSM) then
693 		p_Container_Name := l_Concurrent_Queue_Name;
694 	else
695 		p_Container_Name := l_Standalone_Container_Name;
696 	END IF;
697 
698 EXCEPTION
699   WHEN OTHERS THEN
700     WF_CORE.CONTEXT(pv_Package_Name, 'Get_Container_Info', p_Component_Id);
701   RAISE;
702 end Get_Container_Info;
703 
704 --
705 -- Update_Status
706 --   Procedure to update the status of the given Service Component in
707 --   the FND_SVC_COMPONENTS table and to raise a System Alert if necessary.
708 --   If the component staus is either STOPPED_ERROR or DEACTIVATED_SYSTEM
709 --   then a System Alert is raised with the pre-defined message.
710 --   For more information, refer Bug 3786007.
711 --
712 -- IN
713 --   p_Component_Id       - Component ID
714 --   p_Status             - Status of the Component
715 --   p_Status_Info        - Status Information
716 --   p_Last_Updated_By    - ID of the user who is changing the status
717 --   p_Last_Updated_Login - Login ID of the user who is changing the status
718 --
719 PROCEDURE Update_Status (p_Component_Id      IN NUMBER,
720 			 p_Status            IN VARCHAR2,
721 			 p_Status_Info       IN VARCHAR2,
722 			 p_Last_Updated_By   IN NUMBER,
723 			 p_Last_Update_Login IN NUMBER)
724 is
725    l_component_name fnd_svc_components.component_name%TYPE;
726 
727 begin
728     if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
729         WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_PROCEDURE,
730 			   'wf.plsql.FND_SVC_COMPONENT.UPDATE_STATUS.begin',
731 			   'p_Component_Id: '||p_Component_Id
732 			   ||' p_Status: '||p_Status);
733     end if;
734 
735     UPDATE FND_SVC_COMPONENTS
736     SET    component_status  = p_Status,
737            component_status_info = decode(p_Status_Info, null, component_status_info,
738 					  'NULL', null, substrb(p_Status_Info,1,1996)),
739            last_update_date  = sysdate,
740 	   last_updated_by   = p_Last_Updated_By,
741            last_update_login = p_Last_Update_Login
742     WHERE  component_id = p_Component_Id;
743 
744     -- Check whether the System Alert is to be raised
745     if(upper(p_Status) in ('STOPPED_ERROR', 'DEACTIVATED_SYSTEM')) then
746 
747        -- The  message is logged with UNEXPECTED log level and so it is
748        -- shown as a System Alert in the OAM (apps). In Standalone, the
749        -- wf_log_pkg.set_name, set_token, message methods are empty implementations.
750 
751        -- Set the Message depending on the status
752        if(upper(p_Status) = 'STOPPED_ERROR') then
753 	  WF_LOG_PKG.SET_NAME('FND', 'FND_SVC_ALERT_STOPPED_ERROR');
754        else
755 	  WF_LOG_PKG.SET_NAME('FND', 'FND_SVC_ALERT_SYS_DEACTIVATED');
756        end if;
757 
758        SELECT TRIM(component_name)
759        INTO   l_component_name
760        FROM   fnd_svc_components
761        WHERE  component_id = p_Component_Id;
762 
763        WF_LOG_PKG.SET_TOKEN('COMPONENT_NAME', l_component_name);
764        WF_LOG_PKG.SET_TOKEN('ERROR_CONTEXT', nvl(p_Status_Info,'Not provided.'));
765        WF_LOG_PKG.MESSAGE(WF_LOG_PKG.LEVEL_UNEXPECTED, 'oracle.apps.fnd.cp.gsc', TRUE);
766 
767     end if;
768 
769  EXCEPTION
770   WHEN OTHERS THEN
771     WF_CORE.CONTEXT(pv_Package_Name, 'Update_Status', p_Component_Id, p_Status, p_Status_Info);
772     RAISE;
773 end Update_Status;
774 
775 --
776 -- Get_Component_Status
777 --   Function that returns the current status of the given Component
778 --   after verifying its Container status
779 -- IN
780 --   p_Component_Name     - Component Name
781 --
782 FUNCTION Get_Component_Status
783          (p_Component_Name IN VARCHAR2)
784          RETURN VARCHAR2
785 is
786    l_Component_Id   fnd_svc_comp_requests.component_id%TYPE;
787    l_Container_Type fnd_svc_components.container_type%TYPE;
788    l_Container_Name fnd_svc_components.standalone_container_name%TYPE;
789    l_Current_Status fnd_svc_components.component_status%TYPE;
790 
791 begin
792    -- Get the Component Id
793    SELECT component_id
794    INTO   l_Component_Id
795    FROM   fnd_svc_components
796    WHERE  component_name = p_component_Name;
797 
798    -- Get Container Type and Name
799    Get_Container_Info(p_Component_Id   => l_Component_Id,
800                       p_Container_Type => l_Container_Type,
801                       p_Container_Name => l_Container_Name);
802 
803    -- Verify the Container which will update the Component status if needed
804    Verify_Container (p_container_type => l_container_Type,
805                      p_container_name => l_Container_Name);
806 
807    -- Get Current Status of the Component and return
808    l_Current_Status := Get_Current_Status(p_Component_Id => l_Component_Id);
809    return l_Current_Status;
810 
811 EXCEPTION
812   WHEN OTHERS THEN
813     WF_CORE.CONTEXT(pv_Package_Name, 'Get_Component_Status', p_Component_Name);
814     RAISE;
818 Procedure Raise_Control_Event (p_Component_Id in number,
815 end get_component_status;
816 
817 
819 				p_Control_Operation in varchar2,
820 				p_Container_Type in varchar2,
821 				p_CPID in number,
822 				p_Params in varchar2)
823 is
824 l_event_paramlist wf_parameter_list_t;
825 begin
826 
827     if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
828 	   WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_PROCEDURE,
829 			             'wf.plsql.FND_SVC_COMPONENT.RAISE_CONTROL_EVENT.begin',
830                          'p_Component_Id: '||p_Component_Id||
831                          ', p_Control_Operation:'||p_Control_Operation);
832     end if;
833 
834 	--wf_event.SetDispatchMode ('ASYNC');
835 	l_event_paramlist := wf_parameter_list_t();
836 	if p_Component_Id <> -1 then
837 	    wf_event.addParameterToList('COMPONENT_ID', p_Component_Id, l_event_paramlist);
838 	END IF;
839 	wf_event.addParameterToList('CONTAINER_TYPE', p_Container_Type, l_event_paramlist);
840 	wf_event.addParameterToList('CONTAINER_PROCESS_ID', p_CPID, l_event_paramlist);
841 	if p_Params is not null then
842 		wf_event.addParameterToList('OPERATION_PARAMETERS', p_Params, l_event_paramlist);
843 	END IF;
844 
845 	wf_event.raise(p_Control_Operation, pv_Connection_Name_Prefix||':'||sysdate, null, l_event_paramlist);
846 	--wf_event.SetDispatchMode ('SYNC');
847 
848 EXCEPTION
849   WHEN OTHERS THEN
850     WF_CORE.CONTEXT(pv_Package_Name, 'Raise_Control_Event', p_Component_Id, p_Control_Operation);
851   RAISE;
852 end Raise_Control_Event ;
853 
854 Procedure Start_Component(p_Component_Id in NUMBER,
855 	   	 	p_retcode OUT NOCOPY NUMBER,
856 		 	p_errbuf OUT NOCOPY VARCHAR2)
857 is
858 
859  l_Container_Type fnd_svc_components.container_type%TYPE;
860  l_Container_Name fnd_svc_components.standalone_container_name%TYPE;
861  l_CPID number;
862  l_Container_Status fnd_svc_components.component_status%TYPE;
863 
864 begin
865 	p_retcode := 0;
866 
867     if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
868         WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_PROCEDURE,
869 	                      'wf.plsql.FND_SVC_COMPONENT.START_COMPONENT.begin',
870                           'p_Component_Id: '||p_Component_Id);
871     end if;
872 
873 	Validate_Operation
874 		(p_Component_Id        	=> p_Component_Id,
875 		p_Control_Operation   	=> FND_SVC_COMPONENT.pv_opStart,
876 		p_retcode		=> p_retcode,
877 		p_errbuf		=> p_errbuf);
878 
879 	if p_retcode <> 0 then
880 		return;
881 	END IF;
882 
883 	Get_Container_Info(p_Component_Id 	=> p_Component_Id,
884 			   p_Container_Type 	=> l_Container_Type,
885 			   p_Container_Name 	=> l_Container_Name);
886 
887 	Get_Container_Status (p_container_type => l_Container_Type
888 		         , p_container_name => l_Container_Name
889 			 , p_container_status => l_Container_Status
890 			 , p_process_id	=> l_CPID);
891 
892 	if l_Container_Status <> pv_Container_Status_Running then
893 		raise e_ContainerNotRunning;
894 	end if;
895 
896 	-- Reset the Status Info
897 	Update_Status(p_Component_Id => p_Component_Id,
898 			p_Status => pv_Status_Starting,
899 			p_Status_Info => 'NULL');
900 
901 	Raise_Control_Event (p_Component_Id 	=> p_Component_Id,
902 			p_Control_Operation 	=> pv_Event_Start,
906 
903 			p_Container_Type 	=> l_Container_Type,
904 			p_CPID 			=> l_CPID);
905 exception
907 when e_ContainerNotRunning then
908 	p_retCode := pv_retContainerNotRunning;
909  	p_errbuf := WF_CORE.TRANSLATE ('SVC_CONTAINER_NOT_RUNNING');
910 
911     if (wf_log_pkg.level_error >= fnd_log.g_current_runtime_level) then
912 	   WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_ERROR,
913 	                     'wf.plsql.FND_SVC_COMPONENT.START_COMPONENT.container_not_running',
914                          'Error code: '||p_retCode||' ,Error desc: '||p_errbuf);
915     end if;
916 
917 when others then
918 if SQLCODE <> 0 then
919  	p_retCode := SQLCODE;
920  	p_errbuf :=  SQLERRM;
921 else
922 	p_retCode := pv_retOtherComponentError;
923  	p_errbuf := 'Other non-SQL error';
924 END IF;
925 
926 if (wf_log_pkg.level_error >= fnd_log.g_current_runtime_level) then
927    WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_ERROR,
928                      'wf.plsql.FND_SVC_COMPONENT.START_COMPONENT.error',
929                      'Error code: '||p_retCode||' ,Error desc: '||p_errbuf);
930 end if;
931 
932 End Start_Component;
933 
934 Procedure Stop_Component(p_Component_Id in NUMBER,
935 	   	 	p_retcode OUT NOCOPY NUMBER,
936 		 	p_errbuf OUT NOCOPY VARCHAR2)
937 is
938 
939  l_Container_Type fnd_svc_components.container_type%TYPE;
940  l_Container_Name fnd_svc_components.standalone_container_name%TYPE;
941  l_CPID number;
942  l_Container_Status fnd_svc_components.component_status%TYPE;
943 
944 begin
945 	p_retcode := 0;
946 
947     if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
948 	   WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_PROCEDURE,
949 				         'wf.plsql.FND_SVC_COMPONENT.STOP_COMPONENT.begin',
950 				         'p_Component_Id: '||p_Component_Id);
951     end if;
952 
953 	Validate_Operation
954 		(p_Component_Id        	=> p_Component_Id,
955 		p_Control_Operation   	=> FND_SVC_COMPONENT.pv_opStop,
956 		p_retcode		=> p_retcode,
957 		p_errbuf		=> p_errbuf);
958 
959 	if p_retcode <> 0 then
960 		return;
961 	END IF;
962 
963 	Get_Container_Info(p_Component_Id 	=> p_Component_Id,
964 			   p_Container_Type 	=> l_Container_Type,
965 			   p_Container_Name 	=> l_Container_Name);
966 
967 	Get_Container_Status (p_container_type => l_Container_Type
968 		         , p_container_name => l_Container_Name
969 			 , p_container_status => l_Container_Status
970 			 , p_process_id	=> l_CPID);
971 
972 	if l_Container_Status <> pv_Container_Status_Running then
973 		raise e_ContainerNotRunning;
974 	end if;
975 
976 	Update_Status(p_Component_Id => p_Component_Id, p_Status => pv_Status_Stopping);
977 
978 	Raise_Control_Event (p_Component_Id 	=> p_Component_Id,
979 			p_Control_Operation 	=> pv_Event_Stop,
980 			p_Container_Type 	=> l_Container_Type,
981 			p_CPID 			=> l_CPID);
982 
983 /**********
984 
985 	if (FND_SVC_COMPONENT.pv_callerContext = FND_SVC_COMPONENT.pv_CallerContextUser) then
986 
987 		-- Deactivate the automatic adapter in case user stops it.
988 
989 		if (XDP_ADAPTER_CORE_DB.Is_Adapter_Automatic(p_ChannelName)) then
990 
991 			XDP_ADAPTER_CORE_DB.Update_Status(
992 				p_ChannelName => p_ChannelName,
993 				p_Status => pv_statusDeactivated);
994 		END IF;
995 	END IF;
996 ********/
997 
998 exception
999 
1000 when e_ContainerNotRunning then
1001 	p_retCode := pv_retContainerNotRunning;
1002  	p_errbuf := WF_CORE.TRANSLATE ('SVC_CONTAINER_NOT_RUNNING');
1003 
1004     if (wf_log_pkg.level_error >= fnd_log.g_current_runtime_level) then
1005 	   WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_ERROR,
1006 	                     'wf.plsql.FND_SVC_COMPONENT.STOP_COMPONENT.container_not_running',
1007                          'Error code: '||p_retCode||' ,Error desc: '||p_errbuf);
1008     end if;
1009 
1010 when others then
1011 if SQLCODE <> 0 then
1012  	p_retCode := SQLCODE;
1013  	p_errbuf :=  SQLERRM;
1014 else
1015 	p_retCode := pv_retOtherComponentError;
1016  	p_errbuf := 'Other non-SQL error';
1017 END IF;
1018 if (wf_log_pkg.level_error >= fnd_log.g_current_runtime_level) then
1019    WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_ERROR,
1020                      'wf.plsql.FND_SVC_COMPONENT.STOP_COMPONENT.error',
1021                      'Error code: '||p_retCode||' ,Error desc: '||p_errbuf);
1022 end if;
1023 
1024 end Stop_Component;
1025 
1026 Procedure Suspend_Component(p_Component_Id in NUMBER,
1027 	   	 	p_retcode OUT NOCOPY NUMBER,
1028 		 	p_errbuf OUT NOCOPY VARCHAR2)
1029 is
1030 
1031  l_Container_Type fnd_svc_components.container_type%TYPE;
1032  l_Container_Name fnd_svc_components.standalone_container_name%TYPE;
1033  l_CPID number;
1034  l_Container_Status fnd_svc_components.component_status%TYPE;
1035 
1036 begin
1037 	p_retcode := 0;
1038 
1039     if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
1040 	   WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_PROCEDURE,
1041 				         'wf.plsql.FND_SVC_COMPONENT.SUSPEND_COMPONENT.begin',
1042                          'p_Component_Id: '||p_Component_Id);
1043     end if;
1044 
1045 	Validate_Operation
1046 		(p_Component_Id        	=> p_Component_Id,
1047 		p_Control_Operation   	=> FND_SVC_COMPONENT.pv_opSuspend,
1048 		p_retcode		=> p_retcode,
1049 		p_errbuf		=> p_errbuf);
1050 
1051 	if p_retcode <> 0 then
1052 		return;
1053 	END IF;
1054 
1055 	Get_Container_Info(p_Component_Id 	=> p_Component_Id,
1056 			   p_Container_Type 	=> l_Container_Type,
1057 			   p_Container_Name 	=> l_Container_Name);
1058 
1059 	Get_Container_Status (p_container_type => l_Container_Type
1063 
1060 		         , p_container_name => l_Container_Name
1061 			 , p_container_status => l_Container_Status
1062 			 , p_process_id	=> l_CPID);
1064 	if l_Container_Status <> pv_Container_Status_Running then
1065 		raise e_ContainerNotRunning;
1066 	end if;
1067 
1068 	Update_Status(p_Component_Id => p_Component_Id, p_Status => pv_Status_Suspending);
1069 
1070 	Raise_Control_Event (p_Component_Id 	=> p_Component_Id,
1071 			p_Control_Operation 	=> pv_Event_Suspend,
1072 			p_Container_Type 	=> l_Container_Type,
1073 			p_CPID 			=> l_CPID);
1074 
1075 exception
1076 
1077 when e_ContainerNotRunning then
1078 	p_retCode := pv_retContainerNotRunning;
1079  	p_errbuf := WF_CORE.TRANSLATE ('SVC_CONTAINER_NOT_RUNNING');
1080     if (wf_log_pkg.level_error >= fnd_log.g_current_runtime_level) then
1081        WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_ERROR,
1082                          'wf.plsql.FND_SVC_COMPONENT.SUSPEND_COMPONENT.container_not_running',
1083                          'Error code: '||p_retCode||' ,Error desc: '||p_errbuf);
1084     end if;
1085 
1086 when others then
1087 if SQLCODE <> 0 then
1088  	p_retCode := SQLCODE;
1089  	p_errbuf :=  SQLERRM;
1090 else
1091 	p_retCode := pv_retOtherComponentError;
1092  	p_errbuf := 'Other non-SQL error';
1093 END IF;
1094 
1095 if (wf_log_pkg.level_error >= fnd_log.g_current_runtime_level) then
1096    WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_ERROR,
1097                      'wf.plsql.FND_SVC_COMPONENT.SUSPEND_COMPONENT.error',
1098                      'Error code: '||p_retCode||' ,Error desc: '||p_errbuf);
1099 end if;
1100 
1101 end Suspend_Component;
1102 
1103 Procedure Resume_Component(p_Component_Id in NUMBER,
1104 	   	 	p_retcode OUT NOCOPY NUMBER,
1105 		 	p_errbuf OUT NOCOPY VARCHAR2)
1106 is
1107 
1108  l_Container_Type fnd_svc_components.container_type%TYPE;
1109  l_Container_Name fnd_svc_components.standalone_container_name%TYPE;
1110  l_CPID number;
1111  l_Container_Status fnd_svc_components.component_status%TYPE;
1112 
1113 begin
1114 	p_retcode := 0;
1115 
1116     if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
1117 	   WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_PROCEDURE,
1118                          'wf.plsql.FND_SVC_COMPONENT.RESUME_COMPONENT.begin',
1119                          'p_Component_Id: '||p_Component_Id);
1120     end if;
1121 
1122 	Validate_Operation
1123 		(p_Component_Id        	=> p_Component_Id,
1124 		p_Control_Operation   	=> FND_SVC_COMPONENT.pv_opResume,
1125 		p_retcode		=> p_retcode,
1126 		p_errbuf		=> p_errbuf);
1127 
1128 	if p_retcode <> 0 then
1129 		return;
1130 	END IF;
1131 
1132 	Get_Container_Info(p_Component_Id 	=> p_Component_Id,
1133 			   p_Container_Type 	=> l_Container_Type,
1134 			   p_Container_Name 	=> l_Container_Name);
1135 
1136 	Get_Container_Status (p_container_type => l_Container_Type
1137 		         , p_container_name => l_Container_Name
1138 			 , p_container_status => l_Container_Status
1139 			 , p_process_id	=> l_CPID);
1140 
1141 	if l_Container_Status <> pv_Container_Status_Running then
1142 		raise e_ContainerNotRunning;
1143 	end if;
1144 
1145 	Update_Status(p_Component_Id => p_Component_Id, p_Status => pv_Status_Resuming);
1146 
1147 	Raise_Control_Event (p_Component_Id 	=> p_Component_Id,
1148 			p_Control_Operation 	=> pv_Event_Resume,
1149 			p_Container_Type 	=> l_Container_Type,
1150 			p_CPID 			=> l_CPID);
1151 
1152 exception
1153 
1154 when e_ContainerNotRunning then
1155 	p_retCode := pv_retContainerNotRunning;
1156  	p_errbuf := WF_CORE.TRANSLATE ('SVC_CONTAINER_NOT_RUNNING');
1157 
1158     if (wf_log_pkg.level_error >= fnd_log.g_current_runtime_level) then
1159 	   WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_ERROR,
1160 	                     'wf.plsql.FND_SVC_COMPONENT.RESUME_COMPONENT.container_not_running',
1161                          'Error code: '||p_retCode||' ,Error desc: '||p_errbuf);
1162     end if;
1163 
1164 when others then
1165 if SQLCODE <> 0 then
1166  	p_retCode := SQLCODE;
1167  	p_errbuf :=  SQLERRM;
1168 else
1169 	p_retCode := pv_retOtherComponentError;
1170  	p_errbuf := 'Other non-SQL error';
1171 END IF;
1172 
1173 if (wf_log_pkg.level_error >= fnd_log.g_current_runtime_level) then
1174    WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_ERROR,
1175                      'wf.plsql.FND_SVC_COMPONENT.RESUME_COMPONENT.error',
1176                      'Error code: '||p_retCode||' ,Error desc: '||p_errbuf);
1177 end if;
1178 
1179 end Resume_Component;
1180 
1181 Procedure Refresh_Component(p_Component_Id in NUMBER,
1182 			p_params	IN VARCHAR2,
1183 	   	 	p_retcode OUT NOCOPY NUMBER,
1184 		 	p_errbuf OUT NOCOPY VARCHAR2)
1185 is
1186 
1187  l_Container_Type fnd_svc_components.container_type%TYPE;
1188  l_Container_Name fnd_svc_components.standalone_container_name%TYPE;
1189  l_CPID number;
1190  l_Container_Status fnd_svc_components.component_status%TYPE;
1191 
1192 begin
1193 	p_retcode := 0;
1194 
1195     if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
1196 	   WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_PROCEDURE,
1197 				         'wf.plsql.FND_SVC_COMPONENT.REFRESH_COMPONENT.begin',
1198                          'p_Component_Id: '||p_Component_Id);
1199     end if;
1200 
1201 	Validate_Operation
1202 		(p_Component_Id        	=> p_Component_Id,
1203 		p_Control_Operation   	=> FND_SVC_COMPONENT.pv_opRefresh,
1204 		p_retcode		=> p_retcode,
1205 		p_errbuf		=> p_errbuf);
1206 
1207 	if p_retcode <> 0 then
1208 		return;
1209 	END IF;
1210 
1211 	Get_Container_Info(p_Component_Id 	=> p_Component_Id,
1212 			   p_Container_Type 	=> l_Container_Type,
1213 			   p_Container_Name 	=> l_Container_Name);
1214 
1215 	Get_Container_Status (p_container_type => l_Container_Type
1216 		         , p_container_name => l_Container_Name
1217 			 , p_container_status => l_Container_Status
1218 			 , p_process_id	=> l_CPID);
1219 
1220 	if l_Container_Status <> pv_Container_Status_Running then
1221 		raise e_ContainerNotRunning;
1222 	end if;
1223 
1224 	Raise_Control_Event (p_Component_Id 	=> p_Component_Id,
1225 			p_Control_Operation 	=> pv_Event_Refresh,
1226 			p_Container_Type 	=> l_Container_Type,
1227 			p_CPID 			=> l_CPID,
1228 			p_Params 		=> p_params);
1229 
1230 exception
1231 
1232 when e_ContainerNotRunning then
1233 	p_retCode := pv_retContainerNotRunning;
1234  	p_errbuf := WF_CORE.TRANSLATE ('SVC_CONTAINER_NOT_RUNNING');
1235 
1236  	if (wf_log_pkg.level_error >= fnd_log.g_current_runtime_level) then
1237        WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_ERROR,
1238                          'wf.plsql.FND_SVC_COMPONENT.REFRESH_COMPONENT.container_not_running',
1239                          'Error code: '||p_retCode||' ,Error desc: '||p_errbuf);
1240     end if;
1241 
1242 when others then
1243 if SQLCODE <> 0 then
1244  	p_retCode := SQLCODE;
1245  	p_errbuf :=  SQLERRM;
1246 else
1247 	p_retCode := pv_retOtherComponentError;
1248  	p_errbuf := 'Other non-SQL error';
1249 END IF;
1250 
1251 if (wf_log_pkg.level_error >= fnd_log.g_current_runtime_level) then
1252     WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_ERROR,
1253                       'wf.plsql.FND_SVC_COMPONENT.REFRESH_COMPONENT.error',
1254                       'Error code: '||p_retCode||' ,Error desc: '||p_errbuf);
1255 end if;
1256 
1257 end Refresh_Component;
1258 
1259 Procedure Generic_Operation(p_Component_Id in NUMBER,
1260 			p_Control_Event	IN VARCHAR2,
1261 			p_params	IN VARCHAR2,
1262 	   	 	p_retcode OUT NOCOPY NUMBER,
1263 		 	p_errbuf OUT NOCOPY VARCHAR2)
1264 is
1265 
1266  l_Container_Type fnd_svc_components.container_type%TYPE;
1267  l_Container_Name fnd_svc_components.standalone_container_name%TYPE;
1268  l_CPID number;
1269  l_Container_Status fnd_svc_components.component_status%TYPE;
1270 
1271 begin
1272 	p_retcode := 0;
1273 
1274     if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
1275        WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_PROCEDURE,
1276                          'wf.plsql.FND_SVC_COMPONENT.GENERIC_OPERATION.begin',
1277                          'p_Component_Id: '||p_Component_Id);
1278     end if;
1279 
1280 	Validate_Operation
1281 		(p_Component_Id        	=> p_Component_Id,
1282 		p_Control_Operation   	=> FND_SVC_COMPONENT.pv_opGeneric,
1283 		p_retcode		=> p_retcode,
1284 		p_errbuf		=> p_errbuf);
1285 
1286 	if p_retcode <> 0 then
1287 		return;
1288 	END IF;
1289 
1290 	Get_Container_Info(p_Component_Id 	=> p_Component_Id,
1291 			   p_Container_Type 	=> l_Container_Type,
1292 			   p_Container_Name 	=> l_Container_Name);
1293 
1294 	Get_Container_Status (p_container_type => l_Container_Type
1295 		         , p_container_name => l_Container_Name
1296 			 , p_container_status => l_Container_Status
1297 			 , p_process_id	=> l_CPID);
1298 
1299 	if l_Container_Status <> pv_Container_Status_Running then
1300 		raise e_ContainerNotRunning;
1301 	end if;
1302 
1303 	Raise_Control_Event (p_Component_Id 	=> p_Component_Id,
1304 			p_Control_Operation 	=> p_Control_Event,
1305 			p_Container_Type 	=> l_Container_Type,
1306 			p_CPID 			=> l_CPID,
1307 			p_Params 		=> p_params);
1308 
1309 exception
1310 
1311 when e_ContainerNotRunning then
1312 	p_retCode := pv_retContainerNotRunning;
1313  	p_errbuf := WF_CORE.TRANSLATE ('SVC_CONTAINER_NOT_RUNNING');
1314 
1318                          'Error code: '||p_retCode||' ,Error desc: '||p_errbuf);
1315     if (wf_log_pkg.level_error >= fnd_log.g_current_runtime_level) then
1316        WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_ERROR,
1317                          'wf.plsql.FND_SVC_COMPONENT.GENERIC_OPERATION.container_not_running',
1319     end if;
1320 
1321 when others then
1322 if SQLCODE <> 0 then
1323  	p_retCode := SQLCODE;
1324  	p_errbuf :=  SQLERRM;
1325 else
1326 	p_retCode := pv_retOtherComponentError;
1327  	p_errbuf := 'Other non-SQL error';
1328 END IF;
1329 
1330 if (wf_log_pkg.level_error >= fnd_log.g_current_runtime_level) then
1331    WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_ERROR,
1332                      'wf.plsql.FND_SVC_COMPONENT.GENERIC_OPERATION.error',
1333                      'Error code: '||p_retCode||' ,Error desc: '||p_errbuf);
1334 end if;
1335 
1336 end Generic_Operation;
1337 
1338 Function Get_ConcQ_Name (ApplId in number, ConcQID in number) return varchar2
1339 is
1340 l_ConcQName fnd_concurrent_queues.concurrent_queue_name%TYPE;
1341 begin
1342     select concurrent_queue_name into l_ConcQname from fnd_concurrent_queues
1343         where concurrent_queue_id = ConcQID and application_id = ApplId;
1344 
1345     return l_ConcQName;
1346 end Get_ConcQ_Name;
1347 
1348 Procedure Get_ConcQ_ID (ConcQName in varchar2, ApplId out nocopy number, ConcQId out nocopy number)
1349 is
1350 begin
1351 
1352 select a.concurrent_queue_id, a.application_id into ConcQId, ApplId
1353     from fnd_concurrent_queues a
1354     where a.concurrent_queue_name = ConcQName;
1355 
1356 end Get_ConcQ_ID;
1357 
1358 PROCEDURE Reset_Container_Components
1359          ( p_container_type     IN VARCHAR2
1360          , p_container_name     IN VARCHAR2)
1361 is
1362 PRAGMA AUTONOMOUS_TRANSACTION;
1363 cursor c_Get_Running_Components_Conc (ConcQId number, ApplId number) is
1364     select component_id
1365     from FND_SVC_COMPONENTS
1366     where component_status not in (FND_SVC_COMPONENT.pv_Status_Stopped,
1367                                  FND_SVC_COMPONENT.pv_Status_Stopped_Error,
1368                                  FND_SVC_COMPONENT.pv_Status_Not_Configured,
1369                                  FND_SVC_COMPONENT.pv_Status_Deactivated_User,
1370                                  FND_SVC_COMPONENT.pv_Status_Deactivated_System)
1371                             and container_type = pv_Container_Type_GSM
1372                             and concurrent_queue_id = ConcQId
1373                             and application_id = ApplId;
1374 
1375 cursor c_Get_Running_Components_Std (StdContainerName varchar2) is
1376     select component_id
1377     from FND_SVC_COMPONENTS
1378     where component_status not in (FND_SVC_COMPONENT.pv_Status_Stopped,
1379                                  FND_SVC_COMPONENT.pv_Status_Stopped_Error,
1380                                  FND_SVC_COMPONENT.pv_Status_Not_Configured,
1381                                  FND_SVC_COMPONENT.pv_Status_Deactivated_User,
1382                                  FND_SVC_COMPONENT.pv_Status_Deactivated_System)
1383                             and container_type = pv_Container_Type_Servlet
1384                             and standalone_container_name = StdContainerName;
1385 
1386 l_appl_id number;
1387 l_concurrent_queue_id number;
1388 
1389 begin
1390 
1391     if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
1392        WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_PROCEDURE,
1393                          'wf.plsql.FND_SVC_COMPONENT.RESET_CONTAINER_COMPONENTS.begin',
1394                          'Container Type: '||p_container_type||' Container Name: '||p_container_name);
1395     end if;
1396 
1397     if (p_Container_Type = FND_SVC_COMPONENT.pv_Container_Type_GSM) then
1398 
1399         Get_ConcQ_ID (ConcQName => p_container_name,
1400                       ApplId => l_appl_id, ConcQId => l_concurrent_queue_id);
1401 
1402         FOR r_conc IN c_Get_Running_Components_Conc (l_concurrent_queue_id, l_appl_id) LOOP
1403 
1404             Update_Status (p_Component_Id => r_conc.component_id,
1405                            p_Status => FND_SVC_COMPONENT.pv_Status_Stopped_Error,
1406                            p_Status_Info => 'Status has been reset because the Service Component did not stop gracefully.'); -- TODO MLS??
1407 
1408         END LOOP;
1409 
1410         update FND_SVC_COMPONENTS
1411             set component_status = FND_SVC_COMPONENT.pv_Status_Stopped_Error where
1412             component_status = FND_SVC_COMPONENT.pv_Status_Deactivated_System and
1413             concurrent_queue_id = l_concurrent_queue_id and
1414             application_id = l_appl_id and
1415             container_type = pv_Container_Type_GSM;
1416 
1417     else
1418 
1419         FOR r_std IN c_Get_Running_Components_Std (p_container_name) LOOP
1420 
1421             Update_Status (p_Component_Id => r_std.component_id,
1422                            p_Status => FND_SVC_COMPONENT.pv_Status_Stopped_Error,
1423                            p_Status_Info => 'Status has been reset because the Service Component did not stop gracefully.'); -- TODO MLS??
1424         END LOOP;
1425 
1426         update FND_SVC_COMPONENTS
1427             set component_status = FND_SVC_COMPONENT.pv_Status_Stopped_Error where
1428             component_status = FND_SVC_COMPONENT.pv_Status_Deactivated_System and
1429             standalone_container_name = p_container_name and
1430             container_type = pv_Container_Type_Servlet;
1431 
1432     end if;
1433 
1434     commit;
1435 
1436 EXCEPTION
1437   WHEN OTHERS THEN
1438     WF_CORE.CONTEXT(pv_Package_Name, 'Reset_Container_Components', p_container_type, p_container_name);
1439   RAISE;
1440 
1441 END Reset_Container_Components;
1442 
1446            p_log_level		IN NUMBER,
1443 PROCEDURE Refresh_Container_Log_Level
1444          ( p_container_type     IN VARCHAR2,
1445            p_container_name     IN VARCHAR2,
1447            p_retcode		OUT NOCOPY NUMBER,
1448            p_errbuf		OUT NOCOPY VARCHAR2)
1449 IS
1450 BEGIN
1451 
1452   Refresh_Container
1453   (
1454     p_container_type => p_container_type,
1455     p_container_name => p_container_name,
1456     p_params         => pv_Key_Container_Log_Level || '=' || p_log_level,
1457     p_retcode        => p_retcode,
1458     p_errbuf         => p_errbuf
1459   );
1460 
1461 END Refresh_Container_Log_Level;
1462 
1463 PROCEDURE Refresh_Container
1464          ( p_container_type     IN VARCHAR2,
1465            p_container_name     IN VARCHAR2,
1466            p_params		IN VARCHAR2,
1467            p_retcode		OUT NOCOPY NUMBER,
1468            p_errbuf		OUT NOCOPY VARCHAR2)
1469 is
1470 
1471  l_CPID number;
1472  l_Container_Status fnd_svc_components.component_status%TYPE;
1473 
1474 begin
1475 	p_retcode := 0;
1476 
1477     if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
1478        WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_PROCEDURE,
1479                          'wf.plsql.FND_SVC_COMPONENT.REFRESH_COMPONENT_CONTAINER.begin',
1480                          'p_container_name: '||p_container_name);
1481     end if;
1482 
1483 	Get_Container_Status (p_container_type => p_container_type
1484 		         , p_container_name => p_container_name
1485 			 , p_container_status => l_Container_Status
1486 			 , p_process_id	=> l_CPID);
1487 
1488 	if l_Container_Status <> pv_Container_Status_Running then
1489 		raise e_ContainerNotRunning;
1490 	end if;
1491 
1492 	Raise_Control_Event (p_Control_Operation => pv_Event_Refresh,
1493 			p_Container_Type 	 => p_Container_Type,
1494 			p_CPID 			 => l_CPID,
1495 			p_Params 		 => p_params);
1496 
1497 exception
1498 
1499 when e_ContainerNotRunning then
1500 	p_retCode := pv_retContainerNotRunning;
1501  	p_errbuf := WF_CORE.TRANSLATE ('SVC_CONTAINER_NOT_RUNNING');
1502 
1503     if (wf_log_pkg.level_error >= fnd_log.g_current_runtime_level) then
1504 	   WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_ERROR,
1505 	                     'wf.plsql.FND_SVC_COMPONENT.REFRESH_COMPONENT_CONTAINER.container_not_running',
1506 		                 'Error code: '||p_retCode||' ,Error desc: '||p_errbuf);
1507     end if;
1508 
1509 when others then
1510 if SQLCODE <> 0 then
1511  	p_retCode := SQLCODE;
1512  	p_errbuf :=  SQLERRM;
1513 else
1514 	p_retCode := pv_retOtherComponentError;
1515  	p_errbuf := 'Other non-SQL error';
1516 END IF;
1517 
1518 if (wf_log_pkg.level_error >= fnd_log.g_current_runtime_level) then
1519     WF_LOG_PKG.STRING (WF_LOG_PKG.LEVEL_ERROR,
1520                       'wf.plsql.FND_SVC_COMPONENT.REFRESH_COMPONENT_CONTAINER.error',
1521                       'Error code: '||p_retCode||' ,Error desc: '||p_errbuf);
1522 end if;
1523 
1524 end Refresh_Container;
1525 
1526 PROCEDURE Verify_Container
1527          ( p_container_type     IN VARCHAR2
1528          , p_container_name     IN VARCHAR2)
1529 IS
1530 
1531 l_CPID number;
1532 l_Container_Status fnd_svc_components.component_status%TYPE;
1533 
1534 begin
1535 
1536     Get_Container_Status (p_container_type => p_container_Type
1537                             , p_container_name => p_container_Name
1538                             , p_container_status => l_Container_Status
1539                             , p_process_id	=> l_CPID);
1540 
1541     -- Ignore Running and Stopping Container
1542     if l_Container_Status = pv_Container_Status_Stopped then
1543 
1544        Reset_Container_Components
1545         ( p_container_type     => p_container_type
1546         , p_container_name     => p_container_name);
1547 
1548     end if;
1549 
1550 EXCEPTION
1551   WHEN OTHERS THEN
1552     WF_CORE.CONTEXT(pv_Package_Name, 'Verify_Container', p_container_type, p_container_name);
1553   RAISE;
1554 
1555 end Verify_Container;
1556 
1557 PROCEDURE Verify_All_Containers
1558 IS
1559 
1560 cursor c_Get_Distinct_Containers is
1561 
1562     select distinct standalone_container_name container_name, container_type
1563     from FND_SVC_COMPONENTS
1564     where container_type = pv_Container_Type_Servlet and standalone_container_name is not null
1565 
1566     union
1567 
1568     select distinct concurrent_queue_name container_name, container_type
1569     from FND_SVC_COMPONENTS_V
1570     where container_type = pv_Container_Type_GSM and concurrent_queue_name is not null;
1571 
1572 begin
1573 
1574     FOR r_container IN c_Get_Distinct_Containers LOOP
1575 
1579     END LOOP;
1576         Verify_Container (p_container_type => r_container.container_type,
1577                         p_container_name => r_container.container_name);
1578 
1580 
1581 EXCEPTION
1582   WHEN OTHERS THEN
1583     WF_CORE.CONTEXT(pv_Package_Name, 'Verify_All_Containers');
1584   RAISE;
1585 
1586 end Verify_All_Containers;
1587 
1588 ---------------------------------------------------------------------------
1589 -- Set pkg level private variables
1590 begin
1591   fnd_svc_component.pv_system_guid := hextoraw(wf_core.translate('WF_SYSTEM_GUID'));
1592   fnd_svc_component.pv_schema_name := wf_core.translate('WF_SCHEMA');
1593 
1594   fnd_svc_component.pv_last_agent_name   := ' ';
1595   fnd_svc_component.pv_last_queue_name   := ' ';
1596   fnd_svc_component.pv_last_recipients   := ' ';
1597   pv_install_mode := wf_core.translate('WF_INSTALL');
1598 ---------------------------------------------------------------------------
1599 END FND_SVC_COMPONENT;