Create & Delete managed server by wlst script in Weblogic

Requirement – How to create and delete managed server by wlst script in weblogic

Solutions
As we can use wlst recording feature to generate the script.I have modified a script a little bit

Following script to create a managed server with assigning port and machine.

MakeServer.py

name=sys.argv[1]
port=int(sys.argv[2])
machine=sys.argv[3]
connect('weblogic', 'welcome1', 't3://192.168.0.123:7001')
edit()
startEdit()
cd('/')
cmo.createServer(name)
cd('/Servers/' + name)
cmo.setListenAddress("")
cmo.setListenPort(port)
activate()
startEdit()
cmo.setListenPortEnabled(true)
cmo.setJavaCompiler('javac')
cmo.setClientCertProxyEnabled(false)
cmo.setMachine(getMBean('/Machines/' + machine))
cmo.setCluster(None)
cd('/Servers/' + name + '/SSL/' + name)
cmo.setEnabled(false)
cd('/Servers/NewManagedServer/DataSource/NewManagedServer')
cmo.setRmiJDBCSecurity(None)
activate()

->Open terminal and go to
$MWHOME/wlserver_10.3/server/bin
-> . ./setWLSEnv.sh

-> open new terminal
-> go to $MWHOME/user_project/domains/ucm_domains/bin
-> execute . ./setDomainEnv.sh

:-Note it is like dot space dot/setDomainEnv.sh

Call this script as

java weblogic.WLST /u01/app/oracle/Oracle/middleware/wlserver_10.3/server/bin/MakeServer.py "servername" "portNumber" "MachineName"

___________________________________________________________________________________________________________-

Following script to delete server

DeleteServer.py

name=sys.argv[1]
connect('weblogic', 'welcome1', 't3://192.168.0.123:7001')
edit()
startEdit()
cd('/')
cd('/Servers/' + name)
cmo.setCluster(None)
cmo.setMachine(None)
editService.getConfigurationManager().removeReferencesToBean(getMBean('/Servers/' + name))

cd('/')
cmo.destroyServer(getMBean('/Servers/' + name))

activate()

->Open terminal and go to
$MWHOME/wlserver_10.3/server/bin
-> . ./setWLSEnv.sh

-> open new terminal
-> go to $MWHOME/user_project/domains/ucm_domains/bin
-> execute . ./setDomainEnv.sh

:-Note it is like dot space dot/setDomainEnv.sh

Call this script as

java weblogic.WLST /u01/app/oracle/Oracle/middleware/wlserver_10.3/server/bin/DeleteServer.py "servername"

See the video here

happy learning Weblogic with Vinay kumar in techartifact…..

How to create custom component in Webcenter Content (UCM)

Requirement – How to Create a UCM custom component

Solutions- Please follow the below steps –

Starting the componentWizard – CD to the path where the component wizard is.
[[email protected] ~]$ cd /oracle/Middleware/user_projects/domains/ucm_domain/ucm/cs/bin // this path will of your weblogic domain
[[email protected] bin]$ ./ComponentWizard

1. Goto Options -> Add
You get the below window.
Fill in the component Name. Click OK.

111

You get below screen.
Custom component gets created here (path may be different for you)
/oracle/ecm/ucm_domain/ucm/cs/custom
The component is created and you can add resources by clicking Add.

222

1. Select service. Click next.

333

Fill in the Name of the Service, Service class, Template. Fill in access levels.
Add actions by clicking on Add.

444

5555

Click OK. Click Finish.

Similarly Add a Resource.

666

image

Resources created
demo_component_resource.htm
demo_component_service.htm
demo_component.hda

Modify the resource.htm as below. Give the Service name, handler name and search order.
The handler name is the fully qualified name of the java file where the service method (printTheName()) is created.

Place the compiled java class file in the classes folder inside the custom component.
cs/custom/demo_component/classes/de/xyz/ucm/service

7777

8888

9999

Build the component to create the manifest.hda file. Demo_component.zip is created that can now be installed on other UCM and used.
Build by clicking on Build.

10000

1212212121212

Enable the component.

1313131313

Hit the browser with the service Name and required parameters
http://192.168.0.118:16200/cs/idcplg?IdcService=PRINT_THE_NAME&IsJava=1&dDocName=HO051621920
My java code is as below. (Calls a standard UCM service from my custom service)

package de.xyz.ucm.service;

import java.io.File;
import java.io.IOException;
import intradoc.common.ExecutionContext;
import intradoc.common.LocaleUtils;
import intradoc.common.Log;
import intradoc.common.ServiceException;
import intradoc.common.SystemUtils;
import intradoc.data.DataBinder;
import intradoc.data.DataException;
import intradoc.data.DataResultSet;
import intradoc.data.ResultSet;
import intradoc.data.Workspace;
import intradoc.provider.Provider;
import intradoc.provider.Providers;
import intradoc.server.Service;
import intradoc.server.ServiceData;
import intradoc.server.ServiceHandler;
import intradoc.server.ServiceManager;
import intradoc.server.UserStorage;
import intradoc.shared.SharedObjects;
import intradoc.shared.UserData;

public class PrintingNames extends ServiceHandler{
	public void printTheName() throws DataException, ServiceException
	{
		
	Log.info("Start printing name"+ true);
	String Docname = m_binder.getLocal("dDocName");
	String serviceName = "DOC_INFO_BY_NAME";
    String userName = m_binder.getLocal("dUser");
    Log.info("environment "+m_binder.getEnvironment());
    Log.info("shared obj val"+SharedObjects.getEnvironmentValue("IntradocServerPort"));
	DataBinder requestBinder = new DataBinder();
	requestBinder.putLocal("dDocName", Docname);
	requestBinder.putLocal("IdcService", serviceName);
	
	
	executeService(requestBinder,"sysadmin",false);	
    final ResultSet docinforesultset = requestBinder.getResultSet("DOC_INFO");
    DataResultSet docinfodataresultset = (DataResultSet)requestBinder.getResultSet("DOC_INFO");

 
	DataResultSet result = new DataResultSet();
	result.copy(docinforesultset);
	
	m_binder.putLocal("Message", "Name printed");
	m_binder.addResultSet("demo_resultset1", docinforesultset);
	m_binder.addResultSet("demo_resultset2", docinfodataresultset);
	Log.info("Finished printing name");

	}
	
	public void executeService(DataBinder binder, String userName, boolean suppressServiceError)
	        throws DataException, ServiceException
	    {       
	        ServiceException error;
	        Workspace workspace = getSystemWorkspace();
	        String cmd = binder.getLocal("IdcService");
	        if(cmd == null)
	            throw new DataException("!csIdcServiceMissing");
	        ServiceData serviceData = ServiceManager.getFullService(cmd);
	        if(serviceData == null)
	            throw new DataException(LocaleUtils.encodeMessage("!csNoServiceDefined", null, cmd));
	        Service service = ServiceManager.createService(serviceData.m_classID, workspace, null, binder, serviceData);
	        UserData fullUserData = getFullUserData(userName, service, workspace);
	        service.setUserData(fullUserData);
	        binder.m_environment.put("REMOTE_USER", userName);
	        error = null;
	        try
	        {
	            service.setSendFlags(true, true);
	            service.initDelegatedObjects();
	            service.globalSecurityCheck();
	            service.preActions();
	            service.doActions();
	            service.postActions();
	            service.updateSubjectInformation(true);
	            service.updateTopicInformation(binder);
	      
	        }
	        catch(ServiceException e)
	        {
	            error = e;
	        }
	        finally{
	        service.cleanUp(true);
	        workspace.releaseConnection();
	        }
	        if(error != null)
	            if(suppressServiceError)
	            {
	                error.printStackTrace();
	                if(binder.getLocal("StatusCode") == null)
	                {
	                    binder.putLocal("StatusCode", String.valueOf(error.m_errorCode));
	                    binder.putLocal("StatusMessage", error.getMessage());
	                }
	            } else
	            {
	                throw new ServiceException(error.m_errorCode, error.getMessage());
	            }
	        return;
	    }
	
	public UserData getFullUserData(String userName, ExecutionContext cxt, Workspace ws)
	        throws DataException, ServiceException
	    {
	        if(ws == null)
	            ws = getSystemWorkspace();
	        UserData userData = UserStorage.retrieveUserDatabaseProfileDataFull(userName, ws, null, cxt, true, true);
	        ws.releaseConnection();
	        return userData;
	    }
	
	public static Workspace getSystemWorkspace()
    {
        Workspace workspace = null;
        Provider wsProvider = Providers.getProvider("SystemDatabase");
        if (wsProvider != null)
        {
            workspace = (Workspace) wsProvider.getProvider();
        }
        return workspace;
    }
}

Happy coding with Vinay Kumar in Techartifact…..