Exemple #1
0
def importToALSBDomain():
    try:
        SessionMBean = None

        print 'Attempting to import :', importJar, "on ALSB Admin Server listening on :", adminUrl

        theBytes = readBinaryFile(importJar)
        print 'Read file', importJar
        sessionName = createSessionName()
        print 'Created session', sessionName
        SessionMBean = getSessionManagementMBean(sessionName)
        print 'SessionMBean started session'
        ALSBConfigurationMBean = findService(String("ALSBConfiguration.").concat(sessionName), "com.bea.wli.sb.management.configuration.ALSBConfigurationMBean")
        print "ALSBConfiguration MBean found", ALSBConfigurationMBean
        ALSBConfigurationMBean.uploadJarFile(theBytes)
        print 'Jar Uploaded'

        if project == "None":
            print 'No project specified, additive deployment performed'
            alsbJarInfo = ALSBConfigurationMBean.getImportJarInfo()
            alsbImportPlan = alsbJarInfo.getDefaultImportPlan()
            alsbImportPlan.setPassphrase(passphrase)
            alsbImportPlan.setPreserveExistingEnvValues(true)
            importResult = ALSBConfigurationMBean.importUploaded(alsbImportPlan)
            SessionMBean.activateSession(sessionName, "Complete import without customization using wlst")
        else:
            print 'ALSB project', project, 'will get overlaid'
            alsbJarInfo = ALSBConfigurationMBean.getImportJarInfo()
            alsbImportPlan = alsbJarInfo.getDefaultImportPlan()
            alsbImportPlan.setPassphrase(passphrase)
            operationMap=HashMap()
            operationMap = alsbImportPlan.getOperations()
            print
            print 'Default importPlan'
            printOpMap(operationMap)
            set = operationMap.entrySet()

            alsbImportPlan.setPreserveExistingEnvValues(true)

            #boolean
            abort = false
            #list of created ref
            createdRef = ArrayList()

            for entry in set:
                ref = entry.getKey()
                op = entry.getValue()
                #set different logic based on the resource type
                type = ref.getTypeId
                if type == Refs.SERVICE_ACCOUNT_TYPE or type == Refs.SERVICE_PROVIDER_TYPE:
                    if op.getOperation() == ALSBImportOperation.Operation.Create:
                        print 'Unable to import a service account or a service provider on a target system', ref
                        abort = true
#                elif op.getOperation() == ALSBImportOperation.Operation.Create:
                else:
                    #keep the list of created resources
                    print 'ref: ',ref
                    createdRef.add(ref)

            if abort == true :
                print 'This jar must be imported manually to resolve the service account and service provider dependencies'
                SessionMBean.discardSession(sessionName)
                raise

            print
            print 'Modified importPlan'
            printOpMap(operationMap)
            importResult = ALSBConfigurationMBean.importUploaded(alsbImportPlan)

            printDiagMap(importResult.getImportDiagnostics())

            if importResult.getFailed().isEmpty() == false:
                print 'One or more resources could not be imported properly'
                raise

            #customize if a customization file is specified
            #affects only the created resources
            if customFile != "None" :
                print 'Loading customization File', customFile
                print 'Customization applied to the created resources only', createdRef
                iStream = FileInputStream(customFile)
                customizationList = Customization.fromXML(iStream)
                filteredCustomizationList = ArrayList()
                setRef = HashSet(createdRef)

                # apply a filter to all the customizations to narrow the target to the created resources
                for customization in customizationList:
                    print customization
                    newcustomization = customization.clone(setRef)
                    filteredCustomizationList.add(newcustomization)

                ALSBConfigurationMBean.customize(filteredCustomizationList)

            SessionMBean.activateSession(sessionName, "Complete import with customization using wlst")

        print "Deployment of : " + importJar + " successful"
    except:
        print "Unexpected error:", sys.exc_info()[0]
        if SessionMBean != None:
            SessionMBean.discardSession(sessionName)
        raise
Exemple #2
0
#!/usr/bin/python

from java.io import FileInputStream

propInputStream = FileInputStream(sys.argv[1])
configProps = Properties()
configProps.load(propInputStream)

url = configProps.get("adminUrl")
username = configProps.get("importUser")
password = configProps.get("importPassword")
nmKey = configProps.get("keyName")
exportPath = configProps.get("exportFilePath")
confFile = exportPath+'/'+nmKey+'_config.props'
keyFile = exportPath+'/'+nmKey+'_key.props'

connect(username, password, url)

storeUserConfig(confFile,keyFile)
print("\n[INFO] Generating key and config file\n")
print("Conf file = "+confFile)
print("Key file = "+keyFile+"\n")

disconnect()

exit()
from java.io import FileInputStream
import java.lang
import os
import string

propInputStream = FileInputStream("start.par")
configProps = Properties()
configProps.load(propInputStream)

Username = configProps.get("username")
Password = configProps.get("password")
Host = configProps.get("host")
nmPort = configProps.get("nm.port")
domainName = configProps.get("domain.name")
domainDir = configProps.get("domain.dir")
nmType = configProps.get("nm.type")

connect(Username, Password, 't3://' + Host + ':7001')

clusterNames = configProps.get("cluster.names").split(",")

for cluster in clusterNames:
    print '###### clusterName = ', cluster
    start(cluster, 'Cluster', 't3://' + Host + ':7001', block='true')
    print ''
    print '============================================='
    print '===> Successfully started ', cluster, '  <==='
    print '============================================='
    print ''

disconnect()
Exemple #4
0
 def addManifestFile(self, manifestFile):
   __doc__ = """only one manifest file can be added"""
   self.addManifest(Manifest(FileInputStream(manifestFile)))
Exemple #5
0
from java.io import FileInputStream
import java.lang
import os
import string

propInputStream = FileInputStream('domain.properties')
configProps = Properties()
configProps.load(propInputStream)

wlpath = configProps.get('weblogic.path')
dmpass = configProps.get('domain.password')
dmpath = configProps.get('domain.path')
dmport = configProps.get('domain.port')

print '=========================================='
print '===   Se ha iniciado el proceso        ==='
print '=========================================='
readTemplate(wlpath + '/wlserver/common/templates/wls/wls.jar')
cd('Servers/AdminServer')

print '=========================================='
print '=== Configurando el puerto             ==='
print '=========================================='
set('ListenPort', long(dmport))

cd('/')
cd('Security/base_domain/User/weblogic')
print '=========================================='
print '=== Configurando el password           ==='
print '=========================================='
cmo.setPassword(dmpass)
Exemple #6
0
    opts, args = getopt.getopt(sys.argv[1:], "p:h::", ["properies="])
except getopt.GetoptError:
    print 'create_domain.py -p <path-to-properties-file>'
    sys.exit(2)
for opt, arg in opts:
    if opt == '-h':
        print 'create_domain.py -p <path-to-properties-file>'
        sys.exit()
    elif opt in ("-p", "--properties"):
        properties = arg
print 'properties=', properties

# Load the properties from the properties file.
from java.io import FileInputStream

propInputStream = FileInputStream(properties)
configProps = Properties()
configProps.load(propInputStream)

# Set all variables from values in properties file.
wlsPath = configProps.get("path.wls")
domainConfigPath = configProps.get("path.domain.config")
appConfigPath = configProps.get("path.app.config")
domainName = configProps.get("domain.name")
username = configProps.get("domain.username")
password = configProps.get("domain.password")
adminPort = configProps.get("domain.admin.port")
adminAddress = configProps.get("domain.admin.address")
adminPortSSL = configProps.get("domain.admin.port.ssl")

# Display the variable values.
Exemple #7
0
 def test_io_error(self):
     try:
         FileInputStream('asdf')
     except IOError as ex:
         pass
Exemple #8
0
    def __configure_certificates(self):
        if self.__cert_config is not None:
            # determine existing certificates
            logging.info("Determine existing certificates")
            cert_infos = self.__get_certificate_infos()
            self.__cert_config.set_cert_infos(cert_infos)
            self.__cert_config.update_config_file()

            # apply configured certificates
            logging.info("Configure certificates")
            certs = self.__cert_config.get_certificates()
            es = EntityStoreAPI.wrap(self.__fed_archive.getEntityStore(),
                                     self.__passphrase_in)

            cert_infos = []
            cert = None

            for cert_ref in certs:
                file = self.__resolve_file_path(cert_ref.get_file())
                logging.info("Process alias '%s' (%s): %s" %
                             (cert_ref.get_alias(), cert_ref.get_type(), file))
                if cert_ref.get_type() == "crt":
                    cf = CertificateFactory.getInstance("X.509")
                    if os.path.isfile(file):
                        fis = FileInputStream(file)
                        cert = cf.generateCertificate(fis)
                        self.__add_or_replace_certificate(
                            es, cert_ref.get_alias(), cert)
                    else:
                        if self.__simulation_mode:
                            logging.warning(
                                "[SIMULATION_MODE] Certificate file not found, certificate (CRT) ignored: alias=%s"
                                % (cert_ref.get_alias()))
                            continue
                        else:
                            raise ValueError(
                                "Certificate file not found for alias '%s': %s"
                                % (cert_ref.get_alias(), file))
                elif cert_ref.get_type() == "p12":
                    if os.path.isfile(file):
                        key = self.__get_key_from_p12(file,
                                                      cert_ref.get_password())
                        cert = self.__get_cert_from_p12(
                            file, cert_ref.get_password())
                        self.__add_or_replace_certificate(
                            es, cert_ref.get_alias(), cert, key)
                    else:
                        if self.__simulation_mode:
                            logging.warning(
                                "[SIMULATION_MODE] Certificate file not found, certificate (P12) ignored: alias=%s"
                                % (cert_ref.get_alias()))
                            continue
                        else:
                            raise ValueError(
                                "Certificate file not found for alias '%s': %s"
                                % (cert_ref.get_alias(), file))
                elif cert_ref.get_type() == "empty":
                    self.__remove_certificate(es, cert_ref.get_alias())
                    logging.info("Certificate removed: %s" %
                                 (cert_ref.get_alias()))
                    continue
                else:
                    raise ValueError("Unsupported certificate type: %s" %
                                     (cert_ref.get_type()))

                subject = cert.getSubjectDN().getName()
                not_after = cert.getNotAfter()

                cert_info = CertInfo(cert_ref.get_alias(), subject, not_after)
                logging.info(
                    "Certificate (%s) added/replaced: %s [%s] - %s" %
                    (cert_ref.get_type(), cert_info.get_alias(),
                     cert_info.format_not_after(), cert_info.get_subject()))

                cert_infos.append(cert_info)

            if self.__update_cert_config:
                self.__cert_config.set_update_cert_infos(cert_infos)
                self.__cert_config.update_config_file()

            if self.__expiration_days >= 0:
                logging.info(
                    "Checking for certificate expiration within %i days." %
                    (self.__expiration_days))
                has_expired = False
                for cert_info in cert_infos:
                    expiration_days = cert_info.expiration_in_days()
                    if self.__expiration_days > expiration_days:
                        logging.error("Certificate '%s' expires in %i days!" %
                                      (cert_info.get_alias(), expiration_days))
                        has_expired = True

                if has_expired:
                    raise ValueError(
                        "At least one certificate expires in less than %i days; check log file!"
                        % (self.__expiration_days))

            if not self.__simulation_mode:
                DeploymentArchive.updateConfiguration(self.__fed_archive,
                                                      es.es)
                logging.info("Certificates updated.")
            else:
                logging.info(
                    "[SIMULATION_MODE] Certificates simulation succeeded.")
        return True
Exemple #9
0
def loadJavaProperties(propertyFileName):
    inStream = FileInputStream(propertyFileName)
    properties = Properties()
    properties.load(inStream)

    return properties
Exemple #10
0
 def test_io_exception(self):
     try:
         FileInputStream('asdf')
     except Exception as ex:
         self.assertIn('java.io.FileNotFoundException', str(ex))
Exemple #11
0
def loadProps(configPropFile):
    propInputStream = FileInputStream(configPropFile)
    configProps = Properties()
    configProps.load(propInputStream)
    return configProps
Exemple #12
0
    print "ERROR. Invalid Arguments: " + str(sys.argv)
    print " Usage crDS_zms.py adminuser adminpassword env DatasourceName schemaName"
    print " env=[dev|tst|acc|prd]"
    print " env-var is used to get $env.properties file"
    print " schemaName will be forced to UPPERCASE. Make sure your references in propfile are UPPERCASE"
    exit()

username = sys.argv[1]
password = sys.argv[2]
env = sys.argv[3]
DatasourceName = sys.argv[4]
schemaName = sys.argv[5].upper()  #force uppercase

# setup properties file

propInputStream = FileInputStream(env + ".properties")
configProps = Properties()
configProps.load(propInputStream)

#get env specific props for DS
DBPassword = configProps.get(schemaName + '.Password')
DatabaseServiceName = configProps.get(schemaName + ".DatabaseServiceName")
DatabaseHost = configProps.get(schemaName + ".DatabaseHost")
Targets = configProps.get(schemaName + ".Targets")
TargetType = configProps.get(schemaName + ".TargetType")

if not DatabaseServiceName:
    print "Something went wrong reading the datasource properties with prefix " + schemaName + " from file " + env + ".properties"
    exit()

print "Settings from properties file"
Exemple #13
0
from net.sf.cb2java.copybook import *
from java.io import FileReader
from java.io import FileInputStream
import sys


def recurse(d):
    if d.leaf:
        print d.name + ':' + str(d)
    else:
        print d.name
        for c in d.children():
            recurse(c)


copy = sys.argv[1]
data = sys.argv[2]

copybook = CopybookParser.parse(None, FileReader(copy))
stream = FileInputStream(data)

record = copybook.parseData(stream)
for d in record.children:
    recurse(d)
from java.io import FileInputStream
import java.lang
import os
import string
 
propInputStream = FileInputStream("stop.par")
configProps = Properties()
configProps.load(propInputStream)
 
Username = configProps.get("username")
Password = configProps.get("password")
Host = configProps.get("host")
 
connect(Username,Password,'t3://' + Host + ':7001')
domainRuntime() 
clusterNames = configProps.get("cluster.names").split(",")

for cluster in clusterNames:
	print '###### clusterName = ', cluster
	shutdown(cluster,'Cluster','true',1000,force='true', block='true')
	print ''
	print '============================================='
	print '===> Successfully Shutdown ', cluster, '  <==='
	print '============================================='
	print ''

disconnect(force)
Exemple #15
0
# -*- coding: utf-8 -*-
import sys, os, re
from datetime import date
from java.util import Properties
from java.io import FileInputStream

# Load the properties file.
properties = Properties()
properties.load(FileInputStream('gradle.properties'))

# Set the basic project information.
project = 'Armeria'
project_short = 'Armeria'
copyright = properties.get('inceptionYear') + '-' + str(date.today().year) + ', LINE Corporation'

# Set the project version and release.
# Use the last known stable release if the current version ends with '-SNAPSHOT'.
if re.match(r'^.*-SNAPSHOT$', properties.get('version')):
    release = '0.31.1.Final'
else:
    release = properties.get('version')
version = re.match(r'^[0-9]+\.[0-9]+', release).group(0)

# Export the loaded properties and some useful values into epilogs
rst_epilog = '\n'
rst_epilog += '.. |baseurl| replace:: http://line.github.io/armeria/\n'
propIter = properties.entrySet().iterator()
while propIter.hasNext():
    propEntry = propIter.next()
    if propEntry.getKey() in [ 'release', 'version' ]:
        continue